Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
91999fce
Commit
91999fce
authored
Apr 08, 2017
by
antirez
Browse files
Rax library updated.
Important bugs fixed.
parent
3f9e2322
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/rax.c
View file @
91999fce
...
@@ -186,10 +186,10 @@ raxNode *raxReallocForData(raxNode *n, void *data) {
...
@@ -186,10 +186,10 @@ raxNode *raxReallocForData(raxNode *n, void *data) {
void
raxSetData
(
raxNode
*
n
,
void
*
data
)
{
void
raxSetData
(
raxNode
*
n
,
void
*
data
)
{
n
->
iskey
=
1
;
n
->
iskey
=
1
;
if
(
data
!=
NULL
)
{
if
(
data
!=
NULL
)
{
n
->
isnull
=
0
;
void
**
ndata
=
(
void
**
)
void
**
ndata
=
(
void
**
)
((
char
*
)
n
+
raxNodeCurrentLength
(
n
)
-
sizeof
(
void
*
));
((
char
*
)
n
+
raxNodeCurrentLength
(
n
)
-
sizeof
(
void
*
));
memcpy
(
ndata
,
&
data
,
sizeof
(
data
));
memcpy
(
ndata
,
&
data
,
sizeof
(
data
));
n
->
isnull
=
0
;
}
else
{
}
else
{
n
->
isnull
=
1
;
n
->
isnull
=
1
;
}
}
...
@@ -396,6 +396,7 @@ static inline size_t raxLowWalk(rax *rax, unsigned char *s, size_t len, raxNode
...
@@ -396,6 +396,7 @@ static inline size_t raxLowWalk(rax *rax, unsigned char *s, size_t len, raxNode
position to 0 to signal this node represents
position to 0 to signal this node represents
the searched key. */
the searched key. */
}
}
debugnode
(
"Lookup stop node is"
,
h
);
if
(
stopnode
)
*
stopnode
=
h
;
if
(
stopnode
)
*
stopnode
=
h
;
if
(
plink
)
*
plink
=
parentlink
;
if
(
plink
)
*
plink
=
parentlink
;
if
(
splitpos
&&
h
->
iscompr
)
*
splitpos
=
j
;
if
(
splitpos
&&
h
->
iscompr
)
*
splitpos
=
j
;
...
@@ -424,18 +425,21 @@ int raxInsert(rax *rax, unsigned char *s, size_t len, void *data, void **old) {
...
@@ -424,18 +425,21 @@ int raxInsert(rax *rax, unsigned char *s, size_t len, void *data, void **old) {
* our key. We have just to reallocate the node and make space for the
* our key. We have just to reallocate the node and make space for the
* data pointer. */
* data pointer. */
if
(
i
==
len
&&
(
!
h
->
iscompr
||
j
==
0
/* not in the middle if j is 0 */
))
{
if
(
i
==
len
&&
(
!
h
->
iscompr
||
j
==
0
/* not in the middle if j is 0 */
))
{
debugf
(
"### Insert: node representing key exists
\n
"
);
if
(
!
h
->
iskey
||
h
->
isnull
)
{
h
=
raxReallocForData
(
h
,
data
);
if
(
h
)
memcpy
(
parentlink
,
&
h
,
sizeof
(
h
));
}
if
(
h
==
NULL
)
{
errno
=
ENOMEM
;
return
0
;
}
if
(
h
->
iskey
)
{
if
(
h
->
iskey
)
{
if
(
old
)
*
old
=
raxGetData
(
h
);
if
(
old
)
*
old
=
raxGetData
(
h
);
raxSetData
(
h
,
data
);
raxSetData
(
h
,
data
);
errno
=
0
;
errno
=
0
;
return
0
;
/* Element already exists. */
return
0
;
/* Element already exists. */
}
}
h
=
raxReallocForData
(
h
,
data
);
if
(
h
==
NULL
)
{
errno
=
ENOMEM
;
return
0
;
}
memcpy
(
parentlink
,
&
h
,
sizeof
(
h
));
raxSetData
(
h
,
data
);
raxSetData
(
h
,
data
);
rax
->
numele
++
;
rax
->
numele
++
;
return
1
;
/* Element inserted. */
return
1
;
/* Element inserted. */
...
@@ -734,9 +738,7 @@ int raxInsert(rax *rax, unsigned char *s, size_t len, void *data, void **old) {
...
@@ -734,9 +738,7 @@ int raxInsert(rax *rax, unsigned char *s, size_t len, void *data, void **old) {
}
}
/* We walked the radix tree as far as we could, but still there are left
/* We walked the radix tree as far as we could, but still there are left
* chars in our string. We need to insert the missing nodes.
* chars in our string. We need to insert the missing nodes. */
* Note: while loop never entered if the node was split by ALGO2,
* since i == len. */
while
(
i
<
len
)
{
while
(
i
<
len
)
{
raxNode
*
child
;
raxNode
*
child
;
...
@@ -1091,6 +1093,7 @@ int raxRemove(rax *rax, unsigned char *s, size_t len, void **old) {
...
@@ -1091,6 +1093,7 @@ int raxRemove(rax *rax, unsigned char *s, size_t len, void **old) {
/* This is the core of raxFree(): performs a depth-first scan of the
/* This is the core of raxFree(): performs a depth-first scan of the
* tree and releases all the nodes found. */
* tree and releases all the nodes found. */
void
raxRecursiveFree
(
rax
*
rax
,
raxNode
*
n
)
{
void
raxRecursiveFree
(
rax
*
rax
,
raxNode
*
n
)
{
debugnode
(
"free traversing"
,
n
);
int
numchildren
=
n
->
iscompr
?
1
:
n
->
size
;
int
numchildren
=
n
->
iscompr
?
1
:
n
->
size
;
raxNode
**
cp
=
raxNodeLastChildPtr
(
n
);
raxNode
**
cp
=
raxNodeLastChildPtr
(
n
);
while
(
numchildren
--
)
{
while
(
numchildren
--
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment