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
0b8355de
Commit
0b8355de
authored
Jul 20, 2007
by
Bradley C. Kuszmaul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pma_cursor_next almost works
git-svn-id:
file:///svn/tokudb@20
c7de825b-a66e-492c-adef-691d508d4ae1
parent
44c89c28
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
0 deletions
+124
-0
newbrt/brt-test.c
newbrt/brt-test.c
+49
-0
newbrt/brt.c
newbrt/brt.c
+17
-0
newbrt/pma-test.c
newbrt/pma-test.c
+44
-0
newbrt/pma.c
newbrt/pma.c
+13
-0
newbrt/pma.h
newbrt/pma.h
+1
-0
No files found.
newbrt/brt-test.c
View file @
0b8355de
...
...
@@ -634,7 +634,56 @@ void test_cursor_last_empty(void) {
memory_check_all_free
();
}
void
test_cursor_next
(
void
)
{
const
char
*
n
=
"testbrt.brt"
;
CACHETABLE
ct
;
BRT
brt
;
BRT_CURSOR
cursor
;
int
r
;
DBT
kbt
,
vbt
;
unlink
(
n
);
memory_check_all_free
();
r
=
brt_create_cachetable
(
&
ct
,
0
);
assert
(
r
==
0
);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
r
=
open_brt
(
n
,
0
,
1
,
&
brt
,
1
<<
12
,
ct
);
assert
(
r
==
0
);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
r
=
brt_insert
(
brt
,
"hello"
,
6
,
"there"
,
6
);
r
=
brt_insert
(
brt
,
"byebye"
,
7
,
"byenow"
,
7
);
r
=
brt_cursor
(
brt
,
&
cursor
);
assert
(
r
==
0
);
r
=
ybt_init
(
&
kbt
);
assert
(
r
==
0
);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
r
=
ybt_init
(
&
vbt
);
assert
(
r
==
0
);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
r
=
brt_c_get
(
cursor
,
&
kbt
,
&
vbt
,
DB_NEXT
);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
assert
(
r
==
0
);
assert
(
kbt
.
size
==
7
);
assert
(
memcmp
(
kbt
.
data
,
"byebye"
,
7
)
==
0
);
assert
(
vbt
.
size
==
7
);
assert
(
memcmp
(
vbt
.
data
,
"byenow"
,
7
)
==
0
);
r
=
brt_c_get
(
cursor
,
&
kbt
,
&
vbt
,
DB_NEXT
);
assert
(
r
==
0
);
assert
(
kbt
.
size
==
6
);
assert
(
memcmp
(
kbt
.
data
,
"hello"
,
6
)
==
0
);
assert
(
vbt
.
size
==
6
);
assert
(
memcmp
(
vbt
.
data
,
"there"
,
6
)
==
0
);
r
=
brt_c_get
(
cursor
,
&
kbt
,
&
vbt
,
DB_NEXT
);
assert
(
r
==
DB_NOTFOUND
);
r
=
close_brt
(
brt
);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
r
=
cachetable_close
(
ct
);
assert
(
r
==
0
);
//printf("%s:%d %d alloced\n", __FILE__, __LINE__, get_n_items_malloced()); print_malloced_items();
memory_check_all_free
();
}
static
void
brt_blackbox_test
(
void
)
{
test_cursor_next
();
memory_check_all_free
();
test_multiple_dbs_many
();
memory_check_all_free
();
test_cursor_last_empty
();
memory_check_all_free
();
test_multiple_brts_one_db_one_file
();
memory_check_all_free
();
...
...
newbrt/brt.c
View file @
0b8355de
...
...
@@ -1496,6 +1496,17 @@ int brtcurs_set_position_first (BRT_CURSOR cursor, diskoff off) {
}
}
/* reuqires that the cursor is initialized. */
int
brtcurs_set_position_next
(
BRT_CURSOR
cursor
)
{
int
r
=
pma_cursor_set_position_next
(
cursor
->
pmacurs
);
if
(
r
==
DB_NOTFOUND
)
{
/* We fell off the end of the pma. */
fprintf
(
stderr
,
"Need to deal with falling off the end of the pma in a cursor
\n
"
);
abort
();
}
return
0
;
}
static
int
unpin_cursor
(
BRT_CURSOR
cursor
)
{
BRT
brt
=
cursor
->
brt
;
int
i
;
...
...
@@ -1535,6 +1546,12 @@ int brt_c_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags) {
r
=
brtcurs_set_position_first
(
cursor
,
*
rootp
);
if
(
r
!=
0
)
goto
died0
;
r
=
pma_cget_current
(
cursor
->
pmacurs
,
kbt
,
vbt
);
break
;
case
DB_NEXT
:
if
(
cursor
->
path_len
<
0
)
return
brt_c_get
(
cursor
,
kbt
,
vbt
,
(
flags
&
(
~
DB_NEXT
))
|
DB_FIRST
);
assert
(
cursor
->
path_len
>
0
);
r
=
brtcurs_set_position_next
(
cursor
);
if
(
r
!=
0
)
goto
died0
;
r
=
pma_cget_current
(
cursor
->
pmacurs
,
kbt
,
vbt
);
break
;
default:
fprintf
(
stderr
,
"%s:%d c_get(...,%d) not ready
\n
"
,
__FILE__
,
__LINE__
,
flags
);
abort
();
...
...
newbrt/pma-test.c
View file @
0b8355de
...
...
@@ -417,10 +417,54 @@ void test_pma_cursor_2 (void) {
r
=
pma_free
(
&
pma
);
assert
(
r
==
0
);
}
void
test_pma_cursor_3
(
void
)
{
PMA
pma
;
PMA_CURSOR
c
=
0
;
int
r
;
DBT
key
,
val
;
r
=
pma_create
(
&
pma
);
assert
(
r
==
0
);
r
=
pma_insert
(
pma
,
"x"
,
2
,
"xx"
,
3
);
assert
(
r
==
BRT_OK
);
r
=
pma_insert
(
pma
,
"m"
,
2
,
"mm"
,
3
);
assert
(
r
==
BRT_OK
);
r
=
pma_insert
(
pma
,
"aa"
,
3
,
"a"
,
2
);
assert
(
r
==
BRT_OK
);
ybt_init
(
&
key
);
key
.
flags
=
DB_DBT_REALLOC
;
ybt_init
(
&
val
);
val
.
flags
=
DB_DBT_REALLOC
;
r
=
pma_cursor
(
pma
,
&
c
);
assert
(
r
==
0
);
assert
(
c
!=
0
);
r
=
pma_cursor_set_position_first
(
c
);
assert
(
r
==
0
);
r
=
pma_cget_current
(
c
,
&
key
,
&
val
);
assert
(
r
==
0
);
assert
(
key
.
size
=
3
);
assert
(
memcmp
(
key
.
data
,
"aa"
,
3
)
==
0
);
assert
(
val
.
size
=
2
);
assert
(
memcmp
(
val
.
data
,
"a"
,
2
)
==
0
);
r
=
pma_cursor_set_position_next
(
c
);
assert
(
r
==
0
);
r
=
pma_cget_current
(
c
,
&
key
,
&
val
);
assert
(
r
==
0
);
assert
(
key
.
size
=
2
);
assert
(
memcmp
(
key
.
data
,
"m"
,
2
)
==
0
);
assert
(
val
.
size
=
3
);
assert
(
memcmp
(
val
.
data
,
"mm"
,
3
)
==
0
);
r
=
pma_cursor_set_position_next
(
c
);
assert
(
r
==
0
);
r
=
pma_cget_current
(
c
,
&
key
,
&
val
);
assert
(
r
==
0
);
assert
(
key
.
size
=
2
);
assert
(
memcmp
(
key
.
data
,
"x"
,
2
)
==
0
);
assert
(
val
.
size
=
3
);
assert
(
memcmp
(
val
.
data
,
"xx"
,
3
)
==
0
);
r
=
pma_cursor_set_position_next
(
c
);
assert
(
r
==
DB_NOTFOUND
);
/* After an error, the cursor should still point at the same thing. */
r
=
pma_cget_current
(
c
,
&
key
,
&
val
);
assert
(
r
==
0
);
assert
(
key
.
size
=
2
);
assert
(
memcmp
(
key
.
data
,
"x"
,
2
)
==
0
);
assert
(
val
.
size
=
3
);
assert
(
memcmp
(
val
.
data
,
"xx"
,
3
)
==
0
);
r
=
pma_cursor_set_position_next
(
c
);
assert
(
r
==
DB_NOTFOUND
);
r
=
pma_cursor_free
(
&
c
);
assert
(
r
==
0
);
r
=
pma_free
(
&
pma
);
assert
(
r
==
0
);
}
void
test_pma_cursor
(
void
)
{
test_pma_cursor_0
();
test_pma_cursor_1
();
test_pma_cursor_2
();
test_pma_cursor_3
();
}
void
pma_tests
(
void
)
{
...
...
newbrt/pma.c
View file @
0b8355de
...
...
@@ -330,6 +330,19 @@ int pma_cursor_set_position_first (PMA_CURSOR c)
return
0
;
}
int
pma_cursor_set_position_next
(
PMA_CURSOR
c
)
{
PMA
pma
=
c
->
pma
;
int
old_position
=
c
->
position
;
c
->
position
++
;
while
(
c
->
position
<
pma
->
N
)
{
if
(
c
->
pma
->
pairs
[
c
->
position
].
key
!=
0
)
return
0
;
c
->
position
++
;
}
c
->
position
=
old_position
;
return
DB_NOTFOUND
;
}
int
pma_cget_current
(
PMA_CURSOR
c
,
DBT
*
key
,
DBT
*
val
)
{
PMA
pma
=
c
->
pma
;
if
(
pma
->
pairs
[
c
->
position
].
key
==
0
)
return
BRT_KEYEMPTY
;
...
...
newbrt/pma.h
View file @
0b8355de
...
...
@@ -40,6 +40,7 @@ int pma_cursor_free (PMA_CURSOR*);
int
pma_cursor_set_position_last
(
PMA_CURSOR
c
);
int
pma_cursor_set_position_first
(
PMA_CURSOR
c
);
int
pma_cursor_set_position_next
(
PMA_CURSOR
c
);
/* Requires the cursor is init'd. Returns DB_NOTFOUND if we fall off the end. */
int
pma_cget_current
(
PMA_CURSOR
c
,
DBT
*
key
,
DBT
*
val
);
/* Return PMA_NOTFOUND if the pma is empty. */
...
...
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