There are two alternatives to the hash idea:
- -1- (neat solution, requires a lot of effort) to make the b+tree algorithm polymorphic on its data record and data manipulation methods, so a string will be handled as a string, preserving order by lexicographic ordering.
- -2- (workaround)
to convert each char of a string of 20 chars into 6 bit representing the subgroup of allowed chards, to compose a vector of 4 uint32_t, handled as an atomic group of 4 keys by the current implementation of the b+tree
Thinking about planning
-1-, I wanted to get an idea on the required changes, so I wrote a sugar-module to abstract all the operations made on the key-field by the B+tree algorithm. Changing the key from uint32_t to string only requires the above methods.
void item_clean(p_char_t target);
void item_copy(p_char_t target, p_char_t source);
boolean_t item_cmp_is_grt(p_char_t source0, p_char_t source1); /* A > B */
boolean_t item_cmp_is_get(p_char_t source0, p_char_t source1); /* A >= B*/
boolean_t item_cmp_is_lst(p_char_t source0, p_char_t source1); /* A <B */
boolean_t item_cmp_is_let(p_char_t source0, p_char_t source1); /* A <= B */
boolean_t item_cmp_is_eq(p_char_t source0, p_char_t source1); /* A = B */
boolean_t item_show(p_char_t source0);
void item_input(p_char_t target0);
(methods)
Only the following functions require the above methods:
public p_btree_node_t btree_key_find_leaf /* cmp method */
public btree_ans_t btree_key_find /* cmp method */
public btree_ans_t btree_key_find_star /* cmp method */
private uint32_t node_insert_into_tree_get_insertion_point /* cmp method */
private p_btree_node_t node_insert_into_tree /* cmp method */
private p_btree_node_t node_insert_into_tree_after_splitting /* cmp method */
So I have just modified those functions in the b+tree to use the sugar-code.
OrangeCube # nano project.list.myprj
#item_uint32
item_string
.
OrangeCube # make clean_all
OrangeCube # mybuild-project-makefile-v9
- cleaning all
- touching interface private
- touching interface public
- generating interface private for item_string/lib_btree_item_v1
- generating interface private for app
- generating interface private for app_helper
- generating interface private for lib_block_alloc_v1
- generating interface private for lib_btree_simple_toy_v1
- generating interface public for item_string/lib_btree_item_v1.c
- generating interface public for app.c
- generating interface public for app_helper.c
- generating interface public for lib_block_alloc_v1.c
- generating interface public for lib_btree_simple_toy_v1.c
I have rebuilt the project, so structures are now considering the correct data type for the key (string, instead of integer)
OrangeCube # make
- compiling item_string/lib_btree_item_v1 ... done
- compiling app ... done
- compiling app_helper ... done
- compiling lib_block_alloc_v1 ... done
- compiling lib_btree_simple_toy_v1 ... done
- linking to app
The builder has accepted all the changes without complaing.
OrangeCube # make run
sandbox (out/OrangeCube-HPPA2/app) ...
> h
i: insert
l: leaves
d: delete
f: find
a: find the closest
> i hallo 1
> i hAllo 2
> i hello 3
> i hEllo 4
> i home 5
> i hOme 6
> i hill 7
> i hillside 8
> i hallway 9
> l
+
{ hAllo (2) hEllo (4) hOme (6) hallo (1) hallway (9) }
{ hello (3) hill (7) hillside (8) home (5) }
> g hi
coin_closest {L,R}={home ,hi }
home (5)
> g ha
coin_closest {L,R}={hallway ,ha }
hallway (9)
>
And the result seems working. But this way I have to seriously think about introducing the polymorphism, which means abstracting the data-structure and introducing a mechanism for overloading operators (let_assign, compare{==, <, >, <=, >=}, show, etc) and methods.
At the moment the above code needs to be recompiled for a specific datatype, so if I wanted to go back to integer-keys I would have to do the following
OrangeCube # nano project.list.myprj
item_uint32
#item_string
.
OrangeCube # make clean_all
OrangeCube # mybuild-project-makefile-v9
OrangeCube # make