@@ -33,50 +33,6 @@ namespace ART {
3333 return ;
3434 }
3535 else {
36- /*
37- int lB = (leafValue >> (8 * (maxPrefixLength - 1 - smartIdx))) & 0xFF;
38- if (lB == 255) {
39- printf("tail is changing for %lu\n", value);
40- counter2++;
41- smartIdx--;
42- this->fp_path = {this->root};
43- this->fp_path_length = 1;
44- QuART_stail::insert_recursive_always_change_fp(this, this->root, &this->root, key, 0, value, maxPrefixLength);
45- return;
46- }
47- else if (lB + 1 == key[smartIdx]) {
48- if (smartIdx == 2) {
49- if (key[1] == 0 && key[0] == 0) {
50- printf("tail is changing for %lu\n", value);
51- counter2++;
52- this->fp_path = {this->root};
53- this->fp_path_length = 1;
54- QuART_stail::insert_recursive_always_change_fp(this, this->root, &this->root, key, 0, value, maxPrefixLength);
55- return;
56- }
57- }
58- else if (smartIdx == 1) {
59- if (key[0] == 0) {
60- printf("tail is changing for %lu\n", value);
61- counter2++;
62- this->fp_path = {this->root};
63- this->fp_path_length = 1;
64- QuART_stail::insert_recursive_always_change_fp(this, this->root, &this->root, key, 0, value, maxPrefixLength);
65- return;
66- }
67- }
68- counter3++;
69- //printf("tail is not changing for %lu\n", value);
70- QuART_stail::insert_recursive_only_update_fp(this, this->root, &this->root, key, 0, value, maxPrefixLength);
71- return;
72- }
73- else {
74- counter3++;
75- //printf("tail is not changing for %lu\n", value);
76- QuART_stail::insert_recursive_only_update_fp(this, this->root, &this->root, key, 0, value, maxPrefixLength);
77- return;
78- }
79- */
8036 if (i == 0 ) {
8137 if ((key[0 ] == leafByte + 1 ) && (key[1 ] == 0 ) && (key[2 ] == 0 ) &&
8238 ((leafValue >> 8 * 2 ) & 0xFF ) == 255 && ((leafValue >> 8 ) & 0xFF ) == 255 ) {
@@ -201,6 +157,8 @@ namespace ART {
201157
202158 // If the changing node was the fp just straight change the node
203159 if (tree->fp_leaf == node) {
160+ this ->fp_path [this ->fp_path_length ] = newNode;
161+ this ->fp_path_length ++;
204162 this ->fp = newNode;
205163 this ->fp_ref = nodeRef;
206164 this ->fp_depth = depth + newPrefixLength;
@@ -213,40 +171,58 @@ namespace ART {
213171 return ;
214172 }
215173
216- // Handle prefix of inner node
217- if (node->prefixLength ) {
218- unsigned mismatchPos = prefixMismatch (node, key, depth, maxKeyLength);
219- if (mismatchPos != node->prefixLength ) {
220- // printf("prefix mismatch at node address: %p\n", (void*)node);
221- // Prefix differs, create new node
222- Node4* newNode = new Node4 ();
223- *nodeRef = newNode;
224- newNode->prefixLength = mismatchPos;
225- memcpy (newNode->prefix , node->prefix ,
226- min (mismatchPos, maxPrefixLength));
227- // Break up prefix
228- if (node->prefixLength < maxPrefixLength) {
229- newNode->insertNode4Smart (this , nodeRef, node->prefix [mismatchPos], node);
230- node->prefixLength -= (mismatchPos + 1 );
231- memmove (node->prefix , node->prefix + mismatchPos + 1 ,
232- min (node->prefixLength , maxPrefixLength));
233- } else {
234- node->prefixLength -= (mismatchPos + 1 );
235- uint8_t minKey[maxKeyLength];
236- loadKey (getLeafValue (minimum (node)), minKey);
237- newNode->insertNode4Smart (this , nodeRef, minKey[depth + mismatchPos],
238- node);
239- memmove (node->prefix , minKey + depth + mismatchPos + 1 ,
240- min (node->prefixLength , maxPrefixLength));
174+ // Handle prefix of inner node
175+ if (node->prefixLength ) {
176+ unsigned mismatchPos = prefixMismatch (node, key, depth, maxKeyLength);
177+ if (mismatchPos != node->prefixLength ) {
178+ // Prefix differs, create new node
179+ Node4* newNode = new Node4 ();
180+ *nodeRef = newNode;
181+ newNode->prefixLength = mismatchPos;
182+ memcpy (newNode->prefix , node->prefix ,
183+ min (mismatchPos, maxPrefixLength));
184+ // Break up prefix
185+ if (node->prefixLength < maxPrefixLength) {
186+ // If the nodes that being changed is in fp_path
187+ auto it = std::find (fp_path.begin (), fp_path.begin () + fp_path_length, node);
188+ if (it != fp_path.begin () + fp_path_length) {
189+ // Find the position of node in fp_path
190+ size_t pos = std::distance (fp_path.begin (), it);
191+ std::copy_backward (fp_path.begin () + pos, fp_path.begin () + fp_path_length, fp_path.begin () + fp_path_length + 1 );
192+ fp_path[pos] = newNode;
193+ fp_path_length++;
194+ // tree->fp_depth += node->prefixLength;
195+ }
196+ newNode->insertNode4Smart (this , nodeRef, node->prefix [mismatchPos], node);
197+ node->prefixLength -= (mismatchPos + 1 );
198+ memmove (node->prefix , node->prefix + mismatchPos + 1 ,
199+ min (node->prefixLength , maxPrefixLength));
200+ } else {
201+ node->prefixLength -= (mismatchPos + 1 );
202+ uint8_t minKey[maxKeyLength];
203+ loadKey (getLeafValue (minimum (node)), minKey);
204+ // If the nodes that being changed is in fp_path
205+ auto it = std::find (fp_path.begin (), fp_path.begin () + fp_path_length, node);
206+ if (it != fp_path.begin () + fp_path_length) {
207+ // Find the position of node in fp_path
208+ size_t pos = std::distance (fp_path.begin (), it);
209+ std::copy_backward (fp_path.begin () + pos, fp_path.begin () + fp_path_length, fp_path.begin () + fp_path_length + 1 );
210+ fp_path[pos] = newNode;
211+ fp_path_length++;
212+ // tree->fp_depth += node->prefixLength;
213+ }
214+ newNode->insertNode4Smart (this , nodeRef, minKey[depth + mismatchPos],
215+ node);
216+ memmove (node->prefix , minKey + depth + mismatchPos + 1 ,
217+ min (node->prefixLength , maxPrefixLength));
218+ }
219+ newNode->insertNode4 (this , nodeRef, key[depth + mismatchPos],
220+ makeLeaf (value));
221+ return ;
241222 }
242- // printf("fp_ref points to at the end %p\n", static_cast<void*>(*tree->fp_ref));
243- // printf("nodeRef points to at the end %p\n", static_cast<void*>(*nodeRef));
244- newNode->insertNode4 (this , nodeRef, key[depth + mismatchPos],
245- makeLeaf (value));
246- return ;
223+ depth += node->prefixLength ;
247224 }
248- depth += node->prefixLength ;
249- }
225+
250226
251227 // Recurse
252228 ArtNode** child = findChild (node, key[depth]);
0 commit comments