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
d4fb9f41
Commit
d4fb9f41
authored
Feb 28, 2011
by
antirez
Browse files
encoded types API to get blob length
parent
2cc99365
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/intset.c
View file @
d4fb9f41
...
@@ -222,6 +222,11 @@ uint32_t intsetLen(intset *is) {
...
@@ -222,6 +222,11 @@ uint32_t intsetLen(intset *is) {
return
is
->
length
;
return
is
->
length
;
}
}
/* Return intset blob size in bytes. */
size_t
intsetBlobLen
(
intset
*
is
)
{
return
sizeof
(
intset
)
+
is
->
length
*
is
->
encoding
;
}
#ifdef INTSET_TEST_MAIN
#ifdef INTSET_TEST_MAIN
#include <sys/time.h>
#include <sys/time.h>
...
...
src/intset.h
View file @
d4fb9f41
...
@@ -15,5 +15,6 @@ uint8_t intsetFind(intset *is, int64_t value);
...
@@ -15,5 +15,6 @@ uint8_t intsetFind(intset *is, int64_t value);
int64_t
intsetRandom
(
intset
*
is
);
int64_t
intsetRandom
(
intset
*
is
);
uint8_t
intsetGet
(
intset
*
is
,
uint32_t
pos
,
int64_t
*
value
);
uint8_t
intsetGet
(
intset
*
is
,
uint32_t
pos
,
int64_t
*
value
);
uint32_t
intsetLen
(
intset
*
is
);
uint32_t
intsetLen
(
intset
*
is
);
size_t
intsetBlobLen
(
intset
*
is
);
#endif // __INTSET_H
#endif // __INTSET_H
src/ziplist.c
View file @
d4fb9f41
...
@@ -730,8 +730,8 @@ unsigned int ziplistLen(unsigned char *zl) {
...
@@ -730,8 +730,8 @@ unsigned int ziplistLen(unsigned char *zl) {
return
len
;
return
len
;
}
}
/* Return size in bytes
of ziplist
. */
/* Return
ziplist blob
size in bytes. */
unsigned
in
t
ziplist
Size
(
unsigned
char
*
zl
)
{
size_
t
ziplist
BlobLen
(
unsigned
char
*
zl
)
{
return
ZIPLIST_BYTES
(
zl
);
return
ZIPLIST_BYTES
(
zl
);
}
}
...
...
src/ziplist.h
View file @
d4fb9f41
...
@@ -12,4 +12,4 @@ unsigned char *ziplistDelete(unsigned char *zl, unsigned char **p);
...
@@ -12,4 +12,4 @@ unsigned char *ziplistDelete(unsigned char *zl, unsigned char **p);
unsigned
char
*
ziplistDeleteRange
(
unsigned
char
*
zl
,
unsigned
int
index
,
unsigned
int
num
);
unsigned
char
*
ziplistDeleteRange
(
unsigned
char
*
zl
,
unsigned
int
index
,
unsigned
int
num
);
unsigned
int
ziplistCompare
(
unsigned
char
*
p
,
unsigned
char
*
s
,
unsigned
int
slen
);
unsigned
int
ziplistCompare
(
unsigned
char
*
p
,
unsigned
char
*
s
,
unsigned
int
slen
);
unsigned
int
ziplistLen
(
unsigned
char
*
zl
);
unsigned
int
ziplistLen
(
unsigned
char
*
zl
);
unsigned
in
t
ziplist
Size
(
unsigned
char
*
zl
);
size_
t
ziplist
BlobLen
(
unsigned
char
*
zl
);
src/zipmap.c
View file @
d4fb9f41
...
@@ -144,7 +144,7 @@ static unsigned char *zipmapLookupRaw(unsigned char *zm, unsigned char *key, uns
...
@@ -144,7 +144,7 @@ static unsigned char *zipmapLookupRaw(unsigned char *zm, unsigned char *key, uns
/* Match or skip the key */
/* Match or skip the key */
l
=
zipmapDecodeLength
(
p
);
l
=
zipmapDecodeLength
(
p
);
llen
=
zipmapEncodeLength
(
NULL
,
l
);
llen
=
zipmapEncodeLength
(
NULL
,
l
);
if
(
k
==
NULL
&&
l
==
klen
&&
!
memcmp
(
p
+
llen
,
key
,
l
))
{
if
(
key
!=
NULL
&&
k
==
NULL
&&
l
==
klen
&&
!
memcmp
(
p
+
llen
,
key
,
l
))
{
/* Only return when the user doesn't care
/* Only return when the user doesn't care
* for the total length of the zipmap. */
* for the total length of the zipmap. */
if
(
totlen
!=
NULL
)
{
if
(
totlen
!=
NULL
)
{
...
@@ -364,14 +364,12 @@ unsigned int zipmapLen(unsigned char *zm) {
...
@@ -364,14 +364,12 @@ unsigned int zipmapLen(unsigned char *zm) {
* the zipmap on disk (or everywhere is needed) just writing the returned
* the zipmap on disk (or everywhere is needed) just writing the returned
* amount of bytes of the C array starting at the zipmap pointer. */
* amount of bytes of the C array starting at the zipmap pointer. */
size_t
zipmapBlobLen
(
unsigned
char
*
zm
)
{
size_t
zipmapBlobLen
(
unsigned
char
*
zm
)
{
unsigned
char
*
p
=
zipmapRewind
(
zm
);
unsigned
int
totlen
;
unsigned
char
*
old
=
p
;
zipmapLookupRaw
(
zm
,
NULL
,
0
,
&
totlen
);
while
((
p
=
zipmapNext
(
p
,
NULL
,
NULL
,
NULL
,
NULL
))
!=
NULL
)
{
return
totlen
;
old
=
p
;
}
return
(
old
-
zm
)
+
1
;
}
}
#ifdef ZIPMAP_TEST_MAIN
void
zipmapRepr
(
unsigned
char
*
p
)
{
void
zipmapRepr
(
unsigned
char
*
p
)
{
unsigned
int
l
;
unsigned
int
l
;
...
@@ -405,7 +403,6 @@ void zipmapRepr(unsigned char *p) {
...
@@ -405,7 +403,6 @@ void zipmapRepr(unsigned char *p) {
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
#ifdef ZIPMAP_TEST_MAIN
int
main
(
void
)
{
int
main
(
void
)
{
unsigned
char
*
zm
;
unsigned
char
*
zm
;
...
...
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