Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
be0af2f0
Commit
be0af2f0
authored
Feb 28, 2010
by
antirez
Browse files
minor fixes for zipmap.c
parent
8ec08321
Changes
1
Hide whitespace changes
Inline
Side-by-side
zipmap.c
View file @
be0af2f0
...
@@ -67,14 +67,14 @@
...
@@ -67,14 +67,14 @@
*
*
* The most compact representation of the above two elements hash is actually:
* The most compact representation of the above two elements hash is actually:
*
*
* "\x00\x03
\x00
foo\x03\x00bar\x05
\x00
hello\x05\x00world\xff"
* "\x00\x03foo\x03\x00bar\x05hello\x05\x00world\xff"
*
*
* Empty space is marked using a 254 bytes + a <len> (coded as already
* Empty space is marked using a 254 bytes + a <len> (coded as already
* specified). The length includes the 254 bytes in the count and the
* specified). The length includes the 254 bytes in the count and the
* space taken by the <len> field. So for instance removing the "foo" key
* space taken by the <len> field. So for instance removing the "foo" key
* from the zipmap above will lead to the following representation:
* from the zipmap above will lead to the following representation:
*
*
* "\xfd\x10........\x05
\x00
hello\x05\x00world\xff"
* "\
x00\
xfd\x10........\x05hello\x05\x00world\xff"
*
*
* Note that because empty space, keys, values, are all prefixed length
* Note that because empty space, keys, values, are all prefixed length
* "objects", the lookup will take O(N) where N is the numeber of elements
* "objects", the lookup will take O(N) where N is the numeber of elements
...
@@ -240,9 +240,10 @@ unsigned char *zipmapSet(unsigned char *zm, unsigned char *key, unsigned int kle
...
@@ -240,9 +240,10 @@ unsigned char *zipmapSet(unsigned char *zm, unsigned char *key, unsigned int kle
b
+=
freelen
;
b
+=
freelen
;
freelen
+=
zipmapRawValueLength
(
b
);
freelen
+=
zipmapRawValueLength
(
b
);
if
(
freelen
<
reqlen
)
{
if
(
freelen
<
reqlen
)
{
/* Mark this
blog
as free and recurse */
/* Mark this
entry
as free and recurse */
p
[
0
]
=
ZIPMAP_EMPTY
;
p
[
0
]
=
ZIPMAP_EMPTY
;
zipmapEncodeLength
(
p
+
1
,
freelen
);
zipmapEncodeLength
(
p
+
1
,
freelen
);
zm
[
0
]
|=
ZIPMAP_STATUS_FRAGMENTED
;
return
zipmapSet
(
zm
,
key
,
klen
,
val
,
vlen
);
return
zipmapSet
(
zm
,
key
,
klen
,
val
,
vlen
);
}
}
}
}
...
@@ -322,5 +323,9 @@ int main(void) {
...
@@ -322,5 +323,9 @@ int main(void) {
zm
=
zipmapSet
(
zm
,(
unsigned
char
*
)
"foo"
,
3
,
(
unsigned
char
*
)
"bar"
,
3
);
zm
=
zipmapSet
(
zm
,(
unsigned
char
*
)
"foo"
,
3
,
(
unsigned
char
*
)
"bar"
,
3
);
zm
=
zipmapSet
(
zm
,(
unsigned
char
*
)
"foo"
,
3
,
(
unsigned
char
*
)
"!"
,
1
);
zm
=
zipmapSet
(
zm
,(
unsigned
char
*
)
"foo"
,
3
,
(
unsigned
char
*
)
"!"
,
1
);
zipmapRepr
(
zm
);
zipmapRepr
(
zm
);
zm
=
zipmapSet
(
zm
,(
unsigned
char
*
)
"foo"
,
3
,
(
unsigned
char
*
)
"12345"
,
5
);
zipmapRepr
(
zm
);
zm
=
zipmapSet
(
zm
,(
unsigned
char
*
)
"new"
,
3
,
(
unsigned
char
*
)
"xx"
,
2
);
zipmapRepr
(
zm
);
return
0
;
return
0
;
}
}
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