diff options
author | Chris Robinson <[email protected]> | 2010-05-10 11:40:57 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2010-05-10 11:40:57 -0700 |
commit | 1652dc02abe309b7f7eafca7d9a4f4f81744bc55 (patch) | |
tree | 1444b19ba59501c7661b9fbf7bd535ca59bd0116 /Alc/ALc.c | |
parent | 099c2f3593074c42b736eeb325f8fb259b352dcf (diff) |
Look for the map insertion point using a binary search
Diffstat (limited to 'Alc/ALc.c')
-rw-r--r-- | Alc/ALc.c | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -654,12 +654,23 @@ void ResetUIntMap(UIntMap *map) ALenum InsertUIntMapEntry(UIntMap *map, ALuint key, ALvoid *value) { - ALsizei pos; + ALsizei pos = 0; - for(pos = 0;pos < map->size;pos++) + if(map->size > 0) { - if(map->array[pos].key >= key) - break; + ALsizei low = 0; + ALsizei high = map->size - 1; + while(low < high) + { + ALsizei mid = low + (high-low)/2; + if(map->array[mid].key < key) + low = mid + 1; + else + high = mid; + } + if(map->array[low].key < key) + low++; + pos = low; } if(pos == map->size || map->array[pos].key != key) |