Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
6564575c
Commit
6564575c
authored
Jan 25, 2008
by
Rich Prohaska
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test cursor prev_nodup. addresses #250
git-svn-id:
file:///svn/tokudb@1889
c7de825b-a66e-492c-adef-691d508d4ae1
parent
a61f28f7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
151 additions
and
106 deletions
+151
-106
cxx/tests/test_cursor_count.cpp
cxx/tests/test_cursor_count.cpp
+151
-106
No files found.
cxx/tests/test_cursor_count.cpp
View file @
6564575c
...
...
@@ -19,6 +19,109 @@ int keyeq(Dbt *a, Dbt *b) {
return
memcmp
(
a
->
get_data
(),
b
->
get_data
(),
a
->
get_size
())
==
0
;
}
int
my_cursor_count
(
Dbc
*
cursor
,
db_recno_t
*
count
,
Db
*
db
)
{
int
r
;
Dbt
key
;
key
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
val
;
val
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
key
,
&
val
,
DB_CURRENT
);
assert
(
r
==
0
);
Dbc
*
count_cursor
;
r
=
db
->
cursor
(
0
,
&
count_cursor
,
0
);
assert
(
r
==
0
);
r
=
count_cursor
->
get
(
&
key
,
&
val
,
DB_SET
);
assert
(
r
==
0
);
*
count
=
0
;
Dbt
nkey
,
nval
;
for
(;;
)
{
*
count
+=
1
;
nkey
.
set_flags
(
DB_DBT_REALLOC
);
nval
.
set_flags
(
DB_DBT_REALLOC
);
r
=
count_cursor
->
get
(
&
nkey
,
&
nval
,
DB_NEXT
);
if
(
r
!=
0
)
break
;
if
(
!
keyeq
(
&
key
,
&
nkey
))
break
;
}
r
=
0
;
if
(
nkey
.
get_data
())
free
(
nkey
.
get_data
());
if
(
nval
.
get_data
())
free
(
nval
.
get_data
());
if
(
key
.
get_data
())
free
(
key
.
get_data
());
if
(
val
.
get_data
())
free
(
val
.
get_data
());
int
rr
=
count_cursor
->
close
();
assert
(
rr
==
0
);
return
r
;
}
int
my_next_nodup
(
Dbc
*
cursor
,
Dbt
*
key
,
Dbt
*
val
)
{
int
r
;
Dbt
currentkey
;
currentkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
currentval
;
currentval
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
currentkey
,
&
currentval
,
DB_CURRENT
);
assert
(
r
==
0
);
Dbt
nkey
;
nkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
nval
;
nval
.
set_flags
(
DB_DBT_REALLOC
);
for
(;;)
{
r
=
cursor
->
get
(
&
nkey
,
&
nval
,
DB_NEXT
);
if
(
r
!=
0
)
break
;
if
(
!
keyeq
(
&
currentkey
,
&
nkey
))
break
;
}
if
(
nkey
.
get_data
())
free
(
nkey
.
get_data
());
if
(
nval
.
get_data
())
free
(
nval
.
get_data
());
if
(
currentkey
.
get_data
())
free
(
currentkey
.
get_data
());
if
(
currentval
.
get_data
())
free
(
currentval
.
get_data
());
if
(
r
==
0
)
r
=
cursor
->
get
(
key
,
val
,
DB_CURRENT
);
return
r
;
}
int
my_prev_nodup
(
Dbc
*
cursor
,
Dbt
*
key
,
Dbt
*
val
)
{
int
r
;
Dbt
currentkey
;
currentkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
currentval
;
currentval
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
currentkey
,
&
currentval
,
DB_CURRENT
);
assert
(
r
==
0
);
Dbt
nkey
;
nkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
nval
;
nval
.
set_flags
(
DB_DBT_REALLOC
);
for
(;;)
{
r
=
cursor
->
get
(
&
nkey
,
&
nval
,
DB_PREV
);
if
(
r
!=
0
)
break
;
if
(
!
keyeq
(
&
currentkey
,
&
nkey
))
break
;
}
if
(
nkey
.
get_data
())
free
(
nkey
.
get_data
());
if
(
nval
.
get_data
())
free
(
nval
.
get_data
());
if
(
currentkey
.
get_data
())
free
(
currentkey
.
get_data
());
if
(
currentval
.
get_data
())
free
(
currentval
.
get_data
());
if
(
r
==
0
)
r
=
cursor
->
get
(
key
,
val
,
DB_CURRENT
);
return
r
;
}
int
my_next_dup
(
Dbc
*
cursor
,
Dbt
*
key
,
Dbt
*
val
)
{
int
r
;
Dbt
currentkey
;
currentkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
currentval
;
currentval
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
currentkey
,
&
currentval
,
DB_CURRENT
);
assert
(
r
==
0
);
Dbt
nkey
;
nkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
nval
;
nval
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
nkey
,
&
nval
,
DB_NEXT
);
if
(
r
==
0
&&
!
keyeq
(
&
currentkey
,
&
nkey
))
r
=
DB_NOTFOUND
;
if
(
nkey
.
get_data
())
free
(
nkey
.
get_data
());
if
(
nval
.
get_data
())
free
(
nval
.
get_data
());
if
(
currentkey
.
get_data
())
free
(
currentkey
.
get_data
());
if
(
currentval
.
get_data
())
free
(
currentval
.
get_data
());
if
(
r
==
0
)
r
=
cursor
->
get
(
key
,
val
,
DB_CURRENT
);
return
r
;
}
int
my_prev_dup
(
Dbc
*
cursor
,
Dbt
*
key
,
Dbt
*
val
)
{
int
r
;
Dbt
currentkey
;
currentkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
currentval
;
currentval
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
currentkey
,
&
currentval
,
DB_CURRENT
);
assert
(
r
==
0
);
Dbt
nkey
;
nkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
nval
;
nval
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
nkey
,
&
nval
,
DB_PREV
);
if
(
r
==
0
&&
!
keyeq
(
&
currentkey
,
&
nkey
))
r
=
DB_NOTFOUND
;
if
(
nkey
.
get_data
())
free
(
nkey
.
get_data
());
if
(
nval
.
get_data
())
free
(
nval
.
get_data
());
if
(
currentkey
.
get_data
())
free
(
currentkey
.
get_data
());
if
(
currentval
.
get_data
())
free
(
currentval
.
get_data
());
if
(
r
==
0
)
r
=
cursor
->
get
(
key
,
val
,
DB_CURRENT
);
return
r
;
}
void
load
(
Db
*
db
,
int
n
)
{
if
(
verbose
)
printf
(
"load
\n
"
);
int
i
;
...
...
@@ -40,7 +143,7 @@ void load(Db *db, int n) {
}
}
void
test_cursor_flags
(
Db
*
db
)
{
void
test_cursor_
count_
flags
(
Db
*
db
)
{
int
r
;
Dbc
*
cursor
;
...
...
@@ -53,39 +156,10 @@ void test_cursor_flags(Db *db) {
db_recno_t
n
;
r
=
cursor
->
count
(
&
n
,
1
);
assert
(
r
==
EINVAL
);
r
=
cursor
->
count
(
&
n
,
0
);
assert
(
r
==
0
);
printf
(
"n=%d
\n
"
,
n
);
if
(
verbose
)
printf
(
"n=%d
\n
"
,
n
);
r
=
cursor
->
close
();
assert
(
r
==
0
);
}
int
my_cursor_count
(
Dbc
*
cursor
,
db_recno_t
*
count
,
Db
*
db
)
{
int
r
;
Dbt
key
;
key
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
val
;
val
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
key
,
&
val
,
DB_CURRENT
);
assert
(
r
==
0
);
Dbc
*
count_cursor
;
r
=
db
->
cursor
(
0
,
&
count_cursor
,
0
);
assert
(
r
==
0
);
r
=
count_cursor
->
get
(
&
key
,
&
val
,
DB_SET
);
assert
(
r
==
0
);
*
count
=
0
;
Dbt
nkey
,
nval
;
for
(;;
)
{
*
count
+=
1
;
nkey
.
set_flags
(
DB_DBT_REALLOC
);
nval
.
set_flags
(
DB_DBT_REALLOC
);
r
=
count_cursor
->
get
(
&
nkey
,
&
nval
,
DB_NEXT
);
if
(
r
!=
0
)
break
;
if
(
!
keyeq
(
&
key
,
&
nkey
))
break
;
}
r
=
0
;
if
(
nkey
.
get_data
())
free
(
nkey
.
get_data
());
if
(
nval
.
get_data
())
free
(
nval
.
get_data
());
if
(
key
.
get_data
())
free
(
key
.
get_data
());
if
(
val
.
get_data
())
free
(
val
.
get_data
());
int
rr
=
count_cursor
->
close
();
assert
(
rr
==
0
);
return
r
;
}
void
walk
(
Db
*
db
,
int
n
)
{
if
(
verbose
)
printf
(
"walk
\n
"
);
Dbc
*
cursor
;
...
...
@@ -107,9 +181,11 @@ void walk(Db *db, int n) {
db_recno_t
count
;
r
=
cursor
->
count
(
&
count
,
0
);
assert
(
r
==
0
);
if
(
verbose
)
printf
(
"%d %d %d
\n
"
,
k
,
v
,
count
);
#if 0
db_recno_t mycount;
r = my_cursor_count(cursor, &mycount, db); assert(r == 0);
assert(mycount == count);
#endif
if
(
k
==
n
/
2
)
assert
((
int
)
count
==
n
);
else
assert
(
count
==
1
);
}
assert
(
i
==
2
*
n
-
1
);
...
...
@@ -155,46 +231,6 @@ void test_zero_count(Db *db, int n) {
r
=
cursor
->
close
();
assert
(
r
==
0
);
}
int
my_next_nodup
(
Dbc
*
cursor
,
Dbt
*
key
,
Dbt
*
val
)
{
int
r
;
Dbt
currentkey
;
currentkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
currentval
;
currentval
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
currentkey
,
&
currentval
,
DB_CURRENT
);
assert
(
r
==
0
);
Dbt
nkey
;
nkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
nval
;
nval
.
set_flags
(
DB_DBT_REALLOC
);
for
(;;)
{
r
=
cursor
->
get
(
&
nkey
,
&
nval
,
DB_NEXT
);
if
(
r
!=
0
)
break
;
if
(
!
keyeq
(
&
currentkey
,
&
nkey
))
break
;
}
if
(
nkey
.
get_data
())
free
(
nkey
.
get_data
());
if
(
nval
.
get_data
())
free
(
nval
.
get_data
());
if
(
currentkey
.
get_data
())
free
(
currentkey
.
get_data
());
if
(
currentval
.
get_data
())
free
(
currentval
.
get_data
());
if
(
r
==
0
)
r
=
cursor
->
get
(
key
,
val
,
DB_CURRENT
);
return
r
;
}
int
my_prev_nodup
(
Dbc
*
cursor
,
Dbt
*
key
,
Dbt
*
val
)
{
int
r
;
Dbt
currentkey
;
currentkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
currentval
;
currentval
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
currentkey
,
&
currentval
,
DB_CURRENT
);
assert
(
r
==
0
);
Dbt
nkey
;
nkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
nval
;
nval
.
set_flags
(
DB_DBT_REALLOC
);
for
(;;)
{
r
=
cursor
->
get
(
&
nkey
,
&
nval
,
DB_PREV
);
if
(
r
!=
0
)
break
;
if
(
!
keyeq
(
&
currentkey
,
&
nkey
))
break
;
}
if
(
nkey
.
get_data
())
free
(
nkey
.
get_data
());
if
(
nval
.
get_data
())
free
(
nval
.
get_data
());
if
(
currentkey
.
get_data
())
free
(
currentkey
.
get_data
());
if
(
currentval
.
get_data
())
free
(
currentval
.
get_data
());
if
(
r
==
0
)
r
=
cursor
->
get
(
key
,
val
,
DB_CURRENT
);
return
r
;
}
void
test_next_nodup
(
Db
*
db
,
int
n
)
{
if
(
verbose
)
printf
(
"test_next_nodup
\n
"
);
int
r
;
...
...
@@ -209,9 +245,10 @@ void test_next_nodup(Db *db, int n) {
int
v
=
*
(
int
*
)
val
.
get_data
();
if
(
verbose
)
printf
(
"%d %d
\n
"
,
k
,
v
);
assert
(
k
==
i
);
if
(
k
!=
n
/
2
)
assert
(
v
==
i
);
else
assert
(
v
==
0
);
if
(
k
==
n
/
2
)
assert
(
v
==
0
);
else
assert
(
v
==
i
);
i
+=
1
;
r
=
my_next_nodup
(
cursor
,
&
key
,
&
val
);
// r = my_next_nodup(cursor, &key, &val);
r
=
cursor
->
get
(
&
key
,
&
val
,
DB_NEXT_NODUP
);
}
assert
(
i
==
n
);
if
(
key
.
get_data
())
free
(
key
.
get_data
());
...
...
@@ -219,38 +256,29 @@ void test_next_nodup(Db *db, int n) {
r
=
cursor
->
close
();
assert
(
r
==
0
);
}
int
my_next_dup
(
Dbc
*
cursor
,
Dbt
*
key
,
Dbt
*
val
)
{
int
r
;
Dbt
currentkey
;
currentkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
currentval
;
currentval
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
currentkey
,
&
currentval
,
DB_CURRENT
);
assert
(
r
==
0
);
Dbt
nkey
;
nkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
nval
;
nval
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
nkey
,
&
nval
,
DB_NEXT
);
if
(
r
==
0
&&
!
keyeq
(
&
currentkey
,
&
nkey
))
r
=
DB_NOTFOUND
;
if
(
nkey
.
get_data
())
free
(
nkey
.
get_data
());
if
(
nval
.
get_data
())
free
(
nval
.
get_data
());
if
(
currentkey
.
get_data
())
free
(
currentkey
.
get_data
());
if
(
currentval
.
get_data
())
free
(
currentval
.
get_data
());
if
(
r
==
0
)
r
=
cursor
->
get
(
key
,
val
,
DB_CURRENT
);
return
r
;
}
int
my_prev_dup
(
Dbc
*
cursor
,
Dbt
*
key
,
Dbt
*
val
)
{
void
test_prev_nodup
(
Db
*
db
,
int
n
)
{
if
(
verbose
)
printf
(
"test_prev_nodup
\n
"
);
int
r
;
Dbt
currentkey
;
currentkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
currentval
;
currentval
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
currentkey
,
&
currentval
,
DB_CURRENT
);
assert
(
r
==
0
);
Dbt
nkey
;
nkey
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
nval
;
nval
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
nkey
,
&
nval
,
DB_PREV
);
if
(
r
==
0
&&
!
keyeq
(
&
currentkey
,
&
nkey
))
r
=
DB_NOTFOUND
;
if
(
nkey
.
get_data
())
free
(
nkey
.
get_data
());
if
(
nval
.
get_data
())
free
(
nval
.
get_data
());
if
(
currentkey
.
get_data
())
free
(
currentkey
.
get_data
());
if
(
currentval
.
get_data
())
free
(
currentval
.
get_data
());
if
(
r
==
0
)
r
=
cursor
->
get
(
key
,
val
,
DB_CURRENT
);
return
r
;
Dbc
*
cursor
;
r
=
db
->
cursor
(
0
,
&
cursor
,
0
);
assert
(
r
==
0
);
Dbt
key
;
key
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
val
;
val
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
key
,
&
val
,
DB_LAST
);
assert
(
r
==
0
);
int
i
=
n
-
1
;
while
(
r
==
0
)
{
int
k
=
htonl
(
*
(
int
*
)
key
.
get_data
());
int
v
=
*
(
int
*
)
val
.
get_data
();
if
(
verbose
)
printf
(
"%d %d
\n
"
,
k
,
v
);
assert
(
k
==
i
);
if
(
k
==
n
/
2
)
assert
(
v
==
n
-
1
);
else
assert
(
v
==
i
);
i
-=
1
;
// r = my_next_nodup(cursor, &key, &val);
r
=
cursor
->
get
(
&
key
,
&
val
,
DB_PREV_NODUP
);
}
assert
(
i
==
-
1
);
if
(
key
.
get_data
())
free
(
key
.
get_data
());
if
(
val
.
get_data
())
free
(
val
.
get_data
());
r
=
cursor
->
close
();
assert
(
r
==
0
);
}
void
test_next_dup
(
Db
*
db
,
int
n
)
{
...
...
@@ -271,8 +299,24 @@ void test_next_dup(Db *db, int n) {
if
(
verbose
)
printf
(
"%d %d
\n
"
,
k
,
v
);
assert
(
k
==
n
/
2
);
assert
(
v
==
i
);
i
+=
1
;
r
=
my_next_dup
(
cursor
,
&
key
,
&
val
);
// r = my_next_dup(cursor, &key, &val);
r
=
cursor
->
get
(
&
key
,
&
val
,
DB_NEXT_DUP
);
}
assert
(
i
==
n
);
#ifdef DB_PREV_DUP
i
=
n
-
1
;
for
(;;)
{
r
=
cursor
->
get
(
&
key
,
&
val
,
DB_CURRENT
);
assert
(
r
==
0
);
int
k
=
htonl
(
*
(
int
*
)
key
.
get_data
());
int
v
=
*
(
int
*
)
val
.
get_data
();
assert
(
k
==
n
/
2
);
assert
(
v
==
i
);
r
=
cursor
->
get
(
&
key
,
&
val
,
DB_PREV_DUP
);
if
(
r
!=
0
)
break
;
i
-=
1
;
}
assert
(
i
==
0
);
#endif
if
(
key
.
get_data
())
free
(
key
.
get_data
());
if
(
val
.
get_data
())
free
(
val
.
get_data
());
r
=
cursor
->
close
();
assert
(
r
==
0
);
...
...
@@ -293,9 +337,10 @@ int main(int argc, char *argv[]) {
r
=
db
.
open
(
0
,
"test.db"
,
0
,
DB_BTREE
,
DB_CREATE
,
0777
);
assert
(
r
==
0
);
load
(
&
db
,
10
);
test_cursor_flags
(
&
db
);
test_cursor_
count_
flags
(
&
db
);
walk
(
&
db
,
10
);
test_next_nodup
(
&
db
,
10
);
test_prev_nodup
(
&
db
,
10
);
test_next_dup
(
&
db
,
10
);
test_zero_count
(
&
db
,
10
);
...
...
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