Show More
@@ -32,7 +32,7 b'' | |||||
32 | * A base-16 trie for fast node->rev mapping. |
|
32 | * A base-16 trie for fast node->rev mapping. | |
33 | * |
|
33 | * | |
34 | * Positive value is index of the next node in the trie |
|
34 | * Positive value is index of the next node in the trie | |
35 |
* Negative value is a leaf: -(rev + |
|
35 | * Negative value is a leaf: -(rev + 2) | |
36 | * Zero is empty |
|
36 | * Zero is empty | |
37 | */ |
|
37 | */ | |
38 | typedef struct { |
|
38 | typedef struct { | |
@@ -231,7 +231,7 b' static const char *index_node(indexObjec' | |||||
231 | Py_ssize_t length = index_length(self); |
|
231 | Py_ssize_t length = index_length(self); | |
232 | const char *data; |
|
232 | const char *data; | |
233 |
|
233 | |||
234 |
if (pos == length - 1 || pos == |
|
234 | if (pos == length - 1 || pos == -1) | |
235 | return nullid; |
|
235 | return nullid; | |
236 |
|
236 | |||
237 | if (pos >= length) |
|
237 | if (pos >= length) | |
@@ -1008,7 +1008,7 b' static int nt_find(indexObject *self, co' | |||||
1008 | const char *n; |
|
1008 | const char *n; | |
1009 | Py_ssize_t i; |
|
1009 | Py_ssize_t i; | |
1010 |
|
1010 | |||
1011 |
v = -(v + |
|
1011 | v = -(v + 2); | |
1012 | n = index_node(self, v); |
|
1012 | n = index_node(self, v); | |
1013 | if (n == NULL) |
|
1013 | if (n == NULL) | |
1014 | return -2; |
|
1014 | return -2; | |
@@ -1060,17 +1060,17 b' static int nt_insert(indexObject *self, ' | |||||
1060 | v = n->children[k]; |
|
1060 | v = n->children[k]; | |
1061 |
|
1061 | |||
1062 | if (v == 0) { |
|
1062 | if (v == 0) { | |
1063 |
n->children[k] = -rev - |
|
1063 | n->children[k] = -rev - 2; | |
1064 | return 0; |
|
1064 | return 0; | |
1065 | } |
|
1065 | } | |
1066 | if (v < 0) { |
|
1066 | if (v < 0) { | |
1067 |
const char *oldnode = index_node_existing(self, -(v + |
|
1067 | const char *oldnode = index_node_existing(self, -(v + 2)); | |
1068 | int noff; |
|
1068 | int noff; | |
1069 |
|
1069 | |||
1070 | if (oldnode == NULL) |
|
1070 | if (oldnode == NULL) | |
1071 | return -1; |
|
1071 | return -1; | |
1072 | if (!memcmp(oldnode, node, 20)) { |
|
1072 | if (!memcmp(oldnode, node, 20)) { | |
1073 |
n->children[k] = -rev - |
|
1073 | n->children[k] = -rev - 2; | |
1074 | return 0; |
|
1074 | return 0; | |
1075 | } |
|
1075 | } | |
1076 | noff = nt_new(self); |
|
1076 | noff = nt_new(self); | |
@@ -1095,8 +1095,8 b' static int nt_insert(indexObject *self, ' | |||||
1095 |
|
1095 | |||
1096 | static int nt_delete_node(indexObject *self, const char *node) |
|
1096 | static int nt_delete_node(indexObject *self, const char *node) | |
1097 | { |
|
1097 | { | |
1098 |
/* rev==- |
|
1098 | /* rev==-2 happens to get encoded as 0, which is interpreted as not set */ | |
1099 |
return nt_insert(self, node, - |
|
1099 | return nt_insert(self, node, -2); | |
1100 | } |
|
1100 | } | |
1101 |
|
1101 | |||
1102 | static int nt_init(indexObject *self) |
|
1102 | static int nt_init(indexObject *self) | |
@@ -1118,7 +1118,7 b' static int nt_init(indexObject *self)' | |||||
1118 | self->ntrev = (int)index_length(self) - 1; |
|
1118 | self->ntrev = (int)index_length(self) - 1; | |
1119 | self->ntlookups = 1; |
|
1119 | self->ntlookups = 1; | |
1120 | self->ntmisses = 0; |
|
1120 | self->ntmisses = 0; | |
1121 |
if (nt_insert(self, nullid, |
|
1121 | if (nt_insert(self, nullid, -1) == -1) { | |
1122 | free(self->nt); |
|
1122 | free(self->nt); | |
1123 | self->nt = NULL; |
|
1123 | self->nt = NULL; | |
1124 | return -1; |
|
1124 | return -1; | |
@@ -1290,7 +1290,7 b' static int nt_shortest(indexObject *self' | |||||
1290 | v = n->children[k]; |
|
1290 | v = n->children[k]; | |
1291 | if (v < 0) { |
|
1291 | if (v < 0) { | |
1292 | const char *n; |
|
1292 | const char *n; | |
1293 |
v = -(v + |
|
1293 | v = -(v + 2); | |
1294 | n = index_node_existing(self, v); |
|
1294 | n = index_node_existing(self, v); | |
1295 | if (n == NULL) |
|
1295 | if (n == NULL) | |
1296 | return -3; |
|
1296 | return -3; |
General Comments 0
You need to be logged in to leave comments.
Login now