aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/helpers.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2011-08-30 17:32:49 -0700
committerChris Robinson <[email protected]>2011-08-30 17:32:49 -0700
commit7d577832cd6570480f31fc390ad079bbeeadc692 (patch)
tree9be532f347804bb73a46cc9226edfeab4a748695 /Alc/helpers.c
parentc4866afbe0d4a2b32ca6c409a0ce87f70ac1f693 (diff)
Add functions to retrieve the source from the source map while removing it
Diffstat (limited to 'Alc/helpers.c')
-rw-r--r--Alc/helpers.c29
1 files changed, 29 insertions, 0 deletions
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;
+}