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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
96498c3d
Commit
96498c3d
authored
Jan 10, 2008
by
Rich Prohaska
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
next_dup and prev_dup addresses #259
git-svn-id:
file:///svn/tokudb@1574
c7de825b-a66e-492c-adef-691d508d4ae1
parent
93be128f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
3 deletions
+56
-3
cxx/tests/test_cursor_count.cpp
cxx/tests/test_cursor_count.cpp
+56
-3
No files found.
cxx/tests/test_cursor_count.cpp
View file @
96498c3d
...
...
@@ -145,11 +145,63 @@ void test_next_nodup(Db *db, int n) {
Dbt
key
;
key
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
val
;
val
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
key
,
&
val
,
DB_FIRST
);
assert
(
r
==
0
);
printf
(
"%d %d
\n
"
,
htonl
(
*
(
int
*
)
key
.
get_data
()),
*
(
int
*
)
val
.
get_data
());
for
(;;)
{
while
(
r
==
0
)
{
printf
(
"%d %d
\n
"
,
htonl
(
*
(
int
*
)
key
.
get_data
()),
*
(
int
*
)
val
.
get_data
());
r
=
my_next_nodup
(
cursor
,
&
key
,
&
val
);
if
(
r
!=
0
)
break
;
}
if
(
key
.
get_data
())
free
(
key
.
get_data
());
if
(
val
.
get_data
())
free
(
val
.
get_data
());
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
)
{
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
test_next_dup
(
Db
*
db
,
int
n
)
{
printf
(
"test_next_dup
\n
"
);
int
r
;
Dbc
*
cursor
;
r
=
db
->
cursor
(
0
,
&
cursor
,
0
);
assert
(
r
==
0
);
int
k
=
htonl
(
n
/
2
);
Dbt
setkey
(
&
k
,
sizeof
k
);
Dbt
key
;
key
.
set_flags
(
DB_DBT_REALLOC
);
Dbt
val
;
val
.
set_flags
(
DB_DBT_REALLOC
);
r
=
cursor
->
get
(
&
setkey
,
&
val
,
DB_SET
);
assert
(
r
==
0
);
r
=
cursor
->
get
(
&
key
,
&
val
,
DB_CURRENT
);
assert
(
r
==
0
);
while
(
r
==
0
)
{
printf
(
"%d %d
\n
"
,
htonl
(
*
(
int
*
)
key
.
get_data
()),
*
(
int
*
)
val
.
get_data
());
r
=
my_next_dup
(
cursor
,
&
key
,
&
val
);
}
if
(
key
.
get_data
())
free
(
key
.
get_data
());
if
(
val
.
get_data
())
free
(
val
.
get_data
());
...
...
@@ -166,6 +218,7 @@ int main() {
load
(
&
db
,
10
);
walk
(
&
db
,
10
);
test_next_nodup
(
&
db
,
10
);
test_next_dup
(
&
db
,
10
);
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