Show More
@@ -266,7 +266,7 b' static const char *index_node_existing(i' | |||
|
266 | 266 | return node; |
|
267 | 267 | } |
|
268 | 268 | |
|
269 |
static int nt_insert( |
|
|
269 | static int nt_insert(nodetree *self, const char *node, int rev); | |
|
270 | 270 | |
|
271 | 271 | static int node_check(PyObject *obj, char **node) |
|
272 | 272 | { |
@@ -304,7 +304,7 b' static PyObject *index_append(indexObjec' | |||
|
304 | 304 | return NULL; |
|
305 | 305 | |
|
306 | 306 | if (self->nt) |
|
307 | nt_insert(self, node, len); | |
|
307 | nt_insert(self->nt, node, len); | |
|
308 | 308 | |
|
309 | 309 | Py_CLEAR(self->headrevs); |
|
310 | 310 | Py_RETURN_NONE; |
@@ -978,7 +978,7 b' static inline int nt_level(const char *n' | |||
|
978 | 978 | * -2: not found |
|
979 | 979 | * rest: valid rev |
|
980 | 980 | */ |
|
981 |
static int nt_find( |
|
|
981 | static int nt_find(nodetree *self, const char *node, Py_ssize_t nodelen, | |
|
982 | 982 | int hex) |
|
983 | 983 | { |
|
984 | 984 | int (*getnybble)(const char *, Py_ssize_t) = hex ? hexdigit : nt_level; |
@@ -994,7 +994,7 b' static int nt_find(indexObject *self, co' | |||
|
994 | 994 | |
|
995 | 995 | for (level = off = 0; level < maxlevel; level++) { |
|
996 | 996 | int k = getnybble(node, level); |
|
997 |
nodetreenode *n = &self-> |
|
|
997 | nodetreenode *n = &self->nodes[off]; | |
|
998 | 998 | int v = n->children[k]; |
|
999 | 999 | |
|
1000 | 1000 | if (v < 0) { |
@@ -1002,7 +1002,7 b' static int nt_find(indexObject *self, co' | |||
|
1002 | 1002 | Py_ssize_t i; |
|
1003 | 1003 | |
|
1004 | 1004 | v = -(v + 2); |
|
1005 | n = index_node(self, v); | |
|
1005 | n = index_node(self->index, v); | |
|
1006 | 1006 | if (n == NULL) |
|
1007 | 1007 | return -2; |
|
1008 | 1008 | for (i = level; i < maxlevel; i++) |
@@ -1042,7 +1042,7 b' static int nt_new(nodetree *self)' | |||
|
1042 | 1042 | return self->length++; |
|
1043 | 1043 | } |
|
1044 | 1044 | |
|
1045 |
static int nt_insert( |
|
|
1045 | static int nt_insert(nodetree *self, const char *node, int rev) | |
|
1046 | 1046 | { |
|
1047 | 1047 | int level = 0; |
|
1048 | 1048 | int off = 0; |
@@ -1052,7 +1052,7 b' static int nt_insert(indexObject *self, ' | |||
|
1052 | 1052 | nodetreenode *n; |
|
1053 | 1053 | int v; |
|
1054 | 1054 | |
|
1055 |
n = &self-> |
|
|
1055 | n = &self->nodes[off]; | |
|
1056 | 1056 | v = n->children[k]; |
|
1057 | 1057 | |
|
1058 | 1058 | if (v == 0) { |
@@ -1060,7 +1060,7 b' static int nt_insert(indexObject *self, ' | |||
|
1060 | 1060 | return 0; |
|
1061 | 1061 | } |
|
1062 | 1062 | if (v < 0) { |
|
1063 | const char *oldnode = index_node_existing(self, -(v + 2)); | |
|
1063 | const char *oldnode = index_node_existing(self->index, -(v + 2)); | |
|
1064 | 1064 | int noff; |
|
1065 | 1065 | |
|
1066 | 1066 | if (oldnode == NULL) |
@@ -1069,17 +1069,17 b' static int nt_insert(indexObject *self, ' | |||
|
1069 | 1069 | n->children[k] = -rev - 2; |
|
1070 | 1070 | return 0; |
|
1071 | 1071 | } |
|
1072 |
noff = nt_new(self |
|
|
1072 | noff = nt_new(self); | |
|
1073 | 1073 | if (noff == -1) |
|
1074 | 1074 | return -1; |
|
1075 |
/* self->n |
|
|
1076 |
self |
|
|
1075 | /* self->nodes may have been changed by realloc */ | |
|
1076 | self->nodes[off].children[k] = noff; | |
|
1077 | 1077 | off = noff; |
|
1078 |
n = &self-> |
|
|
1078 | n = &self->nodes[off]; | |
|
1079 | 1079 | n->children[nt_level(oldnode, ++level)] = v; |
|
1080 |
if (level > self-> |
|
|
1081 |
self |
|
|
1082 |
self |
|
|
1080 | if (level > self->depth) | |
|
1081 | self->depth = level; | |
|
1082 | self->splits += 1; | |
|
1083 | 1083 | } else { |
|
1084 | 1084 | level += 1; |
|
1085 | 1085 | off = v; |
@@ -1089,7 +1089,7 b' static int nt_insert(indexObject *self, ' | |||
|
1089 | 1089 | return -1; |
|
1090 | 1090 | } |
|
1091 | 1091 | |
|
1092 |
static int nt_delete_node( |
|
|
1092 | static int nt_delete_node(nodetree *self, const char *node) | |
|
1093 | 1093 | { |
|
1094 | 1094 | /* rev==-2 happens to get encoded as 0, which is interpreted as not set */ |
|
1095 | 1095 | return nt_insert(self, node, -2); |
@@ -1124,7 +1124,7 b' static int nt_init(indexObject *self)' | |||
|
1124 | 1124 | self->nt->splits = 0; |
|
1125 | 1125 | self->nt->length = 1; |
|
1126 | 1126 | self->nt->index = self; |
|
1127 | if (nt_insert(self, nullid, -1) == -1) { | |
|
1127 | if (nt_insert(self->nt, nullid, -1) == -1) { | |
|
1128 | 1128 | free(self->nt->nodes); |
|
1129 | 1129 | PyMem_Free(self->nt); |
|
1130 | 1130 | self->nt = NULL; |
@@ -1150,7 +1150,7 b' static int index_find_node(indexObject *' | |||
|
1150 | 1150 | return -3; |
|
1151 | 1151 | |
|
1152 | 1152 | self->ntlookups++; |
|
1153 | rev = nt_find(self, node, nodelen, 0); | |
|
1153 | rev = nt_find(self->nt, node, nodelen, 0); | |
|
1154 | 1154 | if (rev >= -1) |
|
1155 | 1155 | return rev; |
|
1156 | 1156 | |
@@ -1169,7 +1169,7 b' static int index_find_node(indexObject *' | |||
|
1169 | 1169 | if (n == NULL) |
|
1170 | 1170 | return -3; |
|
1171 | 1171 | if (memcmp(node, n, nodelen > 20 ? 20 : nodelen) == 0) { |
|
1172 | if (nt_insert(self, n, rev) == -1) | |
|
1172 | if (nt_insert(self->nt, n, rev) == -1) | |
|
1173 | 1173 | return -3; |
|
1174 | 1174 | break; |
|
1175 | 1175 | } |
@@ -1179,7 +1179,7 b' static int index_find_node(indexObject *' | |||
|
1179 | 1179 | const char *n = index_node_existing(self, rev); |
|
1180 | 1180 | if (n == NULL) |
|
1181 | 1181 | return -3; |
|
1182 | if (nt_insert(self, n, rev) == -1) { | |
|
1182 | if (nt_insert(self->nt, n, rev) == -1) { | |
|
1183 | 1183 | self->ntrev = rev + 1; |
|
1184 | 1184 | return -3; |
|
1185 | 1185 | } |
@@ -1253,7 +1253,7 b' static int nt_populate(indexObject *self' | |||
|
1253 | 1253 | const char *n = index_node_existing(self, rev); |
|
1254 | 1254 | if (n == NULL) |
|
1255 | 1255 | return -1; |
|
1256 | if (nt_insert(self, n, rev) == -1) | |
|
1256 | if (nt_insert(self->nt, n, rev) == -1) | |
|
1257 | 1257 | return -1; |
|
1258 | 1258 | } |
|
1259 | 1259 | self->ntrev = -1; |
@@ -1261,7 +1261,7 b' static int nt_populate(indexObject *self' | |||
|
1261 | 1261 | return 0; |
|
1262 | 1262 | } |
|
1263 | 1263 | |
|
1264 |
static int nt_partialmatch( |
|
|
1264 | static int nt_partialmatch(nodetree *self, const char *node, | |
|
1265 | 1265 | Py_ssize_t nodelen) |
|
1266 | 1266 | { |
|
1267 | 1267 | return nt_find(self, node, nodelen, 1); |
@@ -1276,19 +1276,19 b' static int nt_partialmatch(indexObject *' | |||
|
1276 | 1276 | * -2: not found (no exception set) |
|
1277 | 1277 | * rest: length of shortest prefix |
|
1278 | 1278 | */ |
|
1279 |
static int nt_shortest( |
|
|
1279 | static int nt_shortest(nodetree *self, const char *node) | |
|
1280 | 1280 | { |
|
1281 | 1281 | int level, off; |
|
1282 | 1282 | |
|
1283 | 1283 | for (level = off = 0; level < 40; level++) { |
|
1284 | 1284 | int k, v; |
|
1285 |
nodetreenode *n = &self-> |
|
|
1285 | nodetreenode *n = &self->nodes[off]; | |
|
1286 | 1286 | k = nt_level(node, level); |
|
1287 | 1287 | v = n->children[k]; |
|
1288 | 1288 | if (v < 0) { |
|
1289 | 1289 | const char *n; |
|
1290 | 1290 | v = -(v + 2); |
|
1291 | n = index_node_existing(self, v); | |
|
1291 | n = index_node_existing(self->index, v); | |
|
1292 | 1292 | if (n == NULL) |
|
1293 | 1293 | return -3; |
|
1294 | 1294 | if (memcmp(node, n, 20) != 0) |
@@ -1345,7 +1345,7 b' static PyObject *index_partialmatch(inde' | |||
|
1345 | 1345 | return NULL; |
|
1346 | 1346 | if (nt_populate(self) == -1) |
|
1347 | 1347 | return NULL; |
|
1348 | rev = nt_partialmatch(self, node, nodelen); | |
|
1348 | rev = nt_partialmatch(self->nt, node, nodelen); | |
|
1349 | 1349 | |
|
1350 | 1350 | switch (rev) { |
|
1351 | 1351 | case -4: |
@@ -1380,7 +1380,7 b' static PyObject *index_shortest(indexObj' | |||
|
1380 | 1380 | return NULL; |
|
1381 | 1381 | if (nt_populate(self) == -1) |
|
1382 | 1382 | return NULL; |
|
1383 | length = nt_shortest(self, node); | |
|
1383 | length = nt_shortest(self->nt, node); | |
|
1384 | 1384 | if (length == -3) |
|
1385 | 1385 | return NULL; |
|
1386 | 1386 | if (length == -2) { |
@@ -1802,7 +1802,7 b' static void nt_invalidate_added(indexObj' | |||
|
1802 | 1802 | PyObject *tuple = PyList_GET_ITEM(self->added, i); |
|
1803 | 1803 | PyObject *node = PyTuple_GET_ITEM(tuple, 7); |
|
1804 | 1804 | |
|
1805 | nt_delete_node(self, PyBytes_AS_STRING(node)); | |
|
1805 | nt_delete_node(self->nt, PyBytes_AS_STRING(node)); | |
|
1806 | 1806 | } |
|
1807 | 1807 | |
|
1808 | 1808 | if (start == 0) |
@@ -1861,7 +1861,7 b' static int index_slice_del(indexObject *' | |||
|
1861 | 1861 | if (node == NULL) |
|
1862 | 1862 | return -1; |
|
1863 | 1863 | |
|
1864 | nt_delete_node(self, node); | |
|
1864 | nt_delete_node(self->nt, node); | |
|
1865 | 1865 | } |
|
1866 | 1866 | if (self->added) |
|
1867 | 1867 | nt_invalidate_added(self, 0); |
@@ -1913,7 +1913,7 b' static int index_assign_subscript(indexO' | |||
|
1913 | 1913 | return -1; |
|
1914 | 1914 | |
|
1915 | 1915 | if (value == NULL) |
|
1916 | return self->nt ? nt_delete_node(self, node) : 0; | |
|
1916 | return self->nt ? nt_delete_node(self->nt, node) : 0; | |
|
1917 | 1917 | rev = PyInt_AsLong(value); |
|
1918 | 1918 | if (rev > INT_MAX || rev < 0) { |
|
1919 | 1919 | if (!PyErr_Occurred()) |
@@ -1923,7 +1923,7 b' static int index_assign_subscript(indexO' | |||
|
1923 | 1923 | |
|
1924 | 1924 | if (nt_init(self) == -1) |
|
1925 | 1925 | return -1; |
|
1926 | return nt_insert(self, node, (int)rev); | |
|
1926 | return nt_insert(self->nt, node, (int)rev); | |
|
1927 | 1927 | } |
|
1928 | 1928 | |
|
1929 | 1929 | /* |
General Comments 0
You need to be logged in to leave comments.
Login now