From: Samual Lenks Date: Fri, 11 Oct 2013 03:11:59 +0000 (-0400) Subject: Add comment for another binary search method X-Git-Tag: xonotic-v0.8.0~256^2~24 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=ebeb5a97fe42aaea05aca9f7b8b4c2e9b77d2a86;p=xonotic%2Fxonotic-data.pk3dir.git Add comment for another binary search method --- diff --git a/qcsrc/menu/xonotic/serverlist.c b/qcsrc/menu/xonotic/serverlist.c index f36a1229c..216a98adb 100644 --- a/qcsrc/menu/xonotic/serverlist.c +++ b/qcsrc/menu/xonotic/serverlist.c @@ -672,6 +672,53 @@ void XonoticServerList_draw(entity me) if(itemcount) { + // binary search method suggested by div + /*float cat = 0, x; + float first, middle, last; + float newfirst = 0; + float catf = 0, catl = 0; + for(x = 1; x <= category_ent_count; ++x) + { + first = newfirst; + last = (itemcount - 1); + middle = floor((first + last) / 2); + + if( + ((catf = gethostcachenumber(SLIST_FIELD_CATEGORY, first)) < x) + && + ((catl = gethostcachenumber(SLIST_FIELD_CATEGORY, last)) >= x) + ) + { + for(;;) + { + cat = gethostcachenumber(SLIST_FIELD_CATEGORY, middle); + if(cat >= x) { last = middle; } + else if(cat < x) { first = middle; } + if((last - middle) == 1) + { + print(sprintf("highhit: x='%d', dc='%d', first='%d', middle='%d', last='%d', cat='%d'.\n", x, category_draw_count, first, middle, last, cat)); + category_name[category_draw_count] = x; + category_item[category_draw_count] = last; + ++category_draw_count; + ++me.nItems; + newfirst = last; // already scanned through these, skip 'em + break; + } + middle = floor((first + last) / 2); + } + } + else if(catf == x) + { + print(sprintf("lowhit: x='%d', dc='%d', first='%d', middle='%d', last='%d', cat='%d'.\n", x, category_draw_count, first, middle, last, catf)); + category_name[category_draw_count] = x; + category_item[category_draw_count] = first; + ++category_draw_count; + ++me.nItems; + newfirst = first + 1; // already scanned through these, skip 'em + } + }*/ + + // my binary search method float cat = 0, x; float first, middle, last; float newfirst = 0; @@ -703,7 +750,8 @@ void XonoticServerList_draw(entity me) middle = floor((first + last) / 2); } } - + + // old linear search method /*float cat = 0, i = 0, x = 0; for(i = 0; i < itemcount; ++i) // FIXME this loop is TOTALLY unacceptable (O(servers)). Make it O(categories * log(servers)). Yes, that is possible. {