Another linked list bites the dust.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3928 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -214,3 +214,28 @@ int tf_util_get_length(JSContext* context, JSValue value)
|
||||
JS_FreeValue(context, length);
|
||||
return result;
|
||||
}
|
||||
|
||||
int tf_util_insert_index(const void* key, const void* base, size_t count, size_t size, int (*compare)(const void*, const void*))
|
||||
{
|
||||
int lower = 0;
|
||||
int upper = count;
|
||||
while (lower < upper && lower < (int)count)
|
||||
{
|
||||
int guess = (lower + upper) / 2;
|
||||
int result = compare(key, ((char*)base) + size * guess);
|
||||
if (result < 0)
|
||||
{
|
||||
upper = guess;
|
||||
}
|
||||
else if (result > 0)
|
||||
{
|
||||
lower = guess + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return guess;
|
||||
}
|
||||
};
|
||||
return lower;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user