-
-
Save Urquelle/ab9f6520e2f2d545aa35207e4b71500a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct BTree; | |
| struct BIterator; | |
| void BTree_Initialize(BTree *tree); | |
| void BTree_Destroy(BTree *tree); | |
| Value *BTree_Get(BTree *tree, Key key); | |
| void BTree_Add(BTree *tree, Key key, Value value); | |
| void BTree_Remove(BTree *tree, Key key); | |
| void BTree_FindStart(BTree *tree, BIterator *iterator); | |
| void BTree_FindEnd(BTree *tree, BIterator *iterator); | |
| void BTree_FindEqualOrGreaterItem(BTree *tree, BIterator *iterator, Key key); | |
| void BTree_FindRange(BTree *tree, BIterator *iterator_start, BIterator *iterator_end, Key key_start, Key key_end); | |
| bool BIterator_Equals(BIterator *iterator1, BIterator *iterator2); | |
| void BIterator_Copy(BIterator *iterator, BIterator *source); | |
| bool BIterator_HasItem(BIterator *iterator); | |
| void BIterator_FindNextItem(BIterator *iterator); | |
| void BIterator_FindNextLeaf(BIterator *iterator); | |
| bool BIterator_HasPreviousItem(BIterator *iterator); | |
| void BIterator_FindPreviousItem(BIterator *iterator); | |
| void BIterator_FindPreviousLeaf(BIterator *iterator); | |
| // Example of simple forward iteration | |
| BIterator iterator; | |
| BTree_FindStart(tree, &iterator); | |
| while (BIterator_HasItem(&iterator)) { | |
| ProcessItem(*iterator.key, *iterator.value); | |
| BIterator_FindNextItem(&iterator); | |
| } | |
| // Example of chunked iteration | |
| extern Value *values; | |
| BIterator iterator; | |
| BTree_FindStart(tree, &iterator); | |
| Value *value = values; | |
| while (BIterator_HasItem(&iterator)) { | |
| int length = iterator.value_end - iterator.value; | |
| CopyMemory(value, iterator.value, length * sizeof(Value)); | |
| value += iterator.length; | |
| BIterator_FindNextLeaf(&iterator); | |
| } | |
| // Example of reverse iteration | |
| BIterator iterator; | |
| BTree_FindEnd(tree, &iterator); | |
| while (BIterator_HasPreviousItem(&iterator)) { | |
| ProcessItem(iterator.key[-1], iterator.value[-1]); | |
| BIterator_FindPreviousItem(&iterator); | |
| } | |
| // Example of range query | |
| extern Key key_start, key_end; | |
| BIterator iterator, iterator_end; | |
| BTree_FindRange(tree, &iterator, &iterator_end, key_start, key_end); | |
| while (!BIterator_Equals(&iterator, &iterator_end)) { | |
| ProcessItem(*iterator.key, *iterator.value); | |
| BIterator_FindNextItem(&iterator); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment