From 7d577832cd6570480f31fc390ad079bbeeadc692 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 30 Aug 2011 17:32:49 -0700 Subject: Add functions to retrieve the source from the source map while removing it --- Alc/helpers.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'Alc/helpers.c') diff --git a/Alc/helpers.c b/Alc/helpers.c index 90bec01c..8aa13111 100644 --- a/Alc/helpers.c +++ b/Alc/helpers.c @@ -431,3 +431,32 @@ ALvoid *LookupUIntMapKey(UIntMap *map, ALuint key) ReadUnlock(&map->lock); return ptr; } + +ALvoid *PopUIntMapValue(UIntMap *map, ALuint key) +{ + ALvoid *ptr = NULL; + WriteLock(&map->lock); + if(map->size > 0) + { + 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) + { + ptr = map->array[low].value; + if(low < map->size-1) + memmove(&map->array[low], &map->array[low+1], + (map->size-1-low)*sizeof(map->array[0])); + map->size--; + } + } + WriteUnlock(&map->lock); + return ptr; +} -- cgit v1.2.3