Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
rust-rocksdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangzongwu
rust-rocksdb
Commits
45d6436f
Commit
45d6436f
authored
Feb 29, 2016
by
Ceri Storey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Format with rustfmt.
parent
e36d9892
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
39 additions
and
39 deletions
+39
-39
comparator.rs
src/comparator.rs
+0
-1
ffi.rs
src/ffi.rs
+14
-12
lib.rs
src/lib.rs
+2
-2
merge_operator.rs
src/merge_operator.rs
+13
-18
rocksdb.rs
src/rocksdb.rs
+0
-0
rocksdb_options.rs
src/rocksdb_options.rs
+10
-6
No files found.
src/comparator.rs
View file @
45d6436f
//
// Copyright 2014 Tyler Neely
// Copyright 2014 Tyler Neely
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// Licensed under the Apache License, Version 2.0 (the "License");
...
...
src/ffi.rs
View file @
45d6436f
//
// Copyright 2014 Tyler Neely
// Copyright 2014 Tyler Neely
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// Licensed under the Apache License, Version 2.0 (the "License");
...
@@ -101,7 +100,7 @@ pub fn error_message(ptr: *const i8) -> String {
...
@@ -101,7 +100,7 @@ pub fn error_message(ptr: *const i8) -> String {
// TODO audit the use of boolean arguments, b/c I think they need to be u8
// TODO audit the use of boolean arguments, b/c I think they need to be u8
// instead...
// instead...
#[link(name
=
"rocksdb"
)]
#[link(name
=
"rocksdb"
)]
extern
{
extern
"C"
{
pub
fn
rocksdb_options_create
()
->
DBOptions
;
pub
fn
rocksdb_options_create
()
->
DBOptions
;
pub
fn
rocksdb_options_destroy
(
opts
:
DBOptions
);
pub
fn
rocksdb_options_destroy
(
opts
:
DBOptions
);
pub
fn
rocksdb_cache_create_lru
(
capacity
:
size_t
)
->
DBCache
;
pub
fn
rocksdb_cache_create_lru
(
capacity
:
size_t
)
->
DBCache
;
...
@@ -191,7 +190,8 @@ extern {
...
@@ -191,7 +190,8 @@ extern {
pub
fn
rocksdb_writeoptions_create
()
->
DBWriteOptions
;
pub
fn
rocksdb_writeoptions_create
()
->
DBWriteOptions
;
pub
fn
rocksdb_writeoptions_destroy
(
writeopts
:
DBWriteOptions
);
pub
fn
rocksdb_writeoptions_destroy
(
writeopts
:
DBWriteOptions
);
pub
fn
rocksdb_writeoptions_set_sync
(
writeopts
:
DBWriteOptions
,
v
:
bool
);
pub
fn
rocksdb_writeoptions_set_sync
(
writeopts
:
DBWriteOptions
,
v
:
bool
);
pub
fn
rocksdb_writeoptions_disable_WAL
(
writeopts
:
DBWriteOptions
,
v
:
c_int
);
pub
fn
rocksdb_writeoptions_disable_WAL
(
writeopts
:
DBWriteOptions
,
v
:
c_int
);
pub
fn
rocksdb_put
(
db
:
DBInstance
,
pub
fn
rocksdb_put
(
db
:
DBInstance
,
writeopts
:
DBWriteOptions
,
writeopts
:
DBWriteOptions
,
k
:
*
const
u8
,
k
:
*
const
u8
,
...
@@ -378,15 +378,17 @@ extern {
...
@@ -378,15 +378,17 @@ extern {
// Comparator
// Comparator
pub
fn
rocksdb_options_set_comparator
(
options
:
DBOptions
,
pub
fn
rocksdb_options_set_comparator
(
options
:
DBOptions
,
cb
:
DBComparator
);
cb
:
DBComparator
);
pub
fn
rocksdb_comparator_create
(
pub
fn
rocksdb_comparator_create
(
state
:
*
mut
c_void
,
state
:
*
mut
c_void
,
destroy
:
extern
"C"
fn
(
*
mut
c_void
)
->
(),
destroy
:
extern
fn
(
*
mut
c_void
)
->
(),
compare
:
extern
"C"
fn
(
arg
:
*
mut
c_void
,
compare
:
extern
fn
(
arg
:
*
mut
c_void
,
a
:
*
const
c_char
,
a
:
*
const
c_char
,
alen
:
size_t
,
alen
:
size_t
,
b
:
*
const
c_char
,
blen
:
size_t
b
:
*
const
c_char
,
)
->
c_int
,
blen
:
size_t
)
name_fn
:
extern
fn
(
*
mut
c_void
)
->
*
const
c_char
->
c_int
,
)
->
DBComparator
;
name_fn
:
extern
"C"
fn
(
*
mut
c_void
)
->
*
const
c_char
)
->
DBComparator
;
pub
fn
rocksdb_comparator_destroy
(
cmp
:
DBComparator
);
pub
fn
rocksdb_comparator_destroy
(
cmp
:
DBComparator
);
// Column Family
// Column Family
...
...
src/lib.rs
View file @
45d6436f
//
// Copyright 2014 Tyler Neely
// Copyright 2014 Tyler Neely
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// Licensed under the Apache License, Version 2.0 (the "License");
...
@@ -15,7 +14,8 @@
...
@@ -15,7 +14,8 @@
//
//
pub
use
ffi
as
rocksdb_ffi
;
pub
use
ffi
as
rocksdb_ffi
;
pub
use
ffi
::{
DBCompactionStyle
,
DBComparator
,
new_bloom_filter
};
pub
use
ffi
::{
DBCompactionStyle
,
DBComparator
,
new_bloom_filter
};
pub
use
rocksdb
::{
DB
,
DBIterator
,
DBVector
,
Direction
,
Writable
,
WriteBatch
,
IteratorMode
};
pub
use
rocksdb
::{
DB
,
DBIterator
,
DBVector
,
Direction
,
IteratorMode
,
Writable
,
WriteBatch
};
pub
use
rocksdb_options
::{
BlockBasedOptions
,
Options
,
WriteOptions
};
pub
use
rocksdb_options
::{
BlockBasedOptions
,
Options
,
WriteOptions
};
pub
use
merge_operator
::
MergeOperands
;
pub
use
merge_operator
::
MergeOperands
;
pub
mod
rocksdb
;
pub
mod
rocksdb
;
...
...
src/merge_operator.rs
View file @
45d6436f
//
// Copyright 2014 Tyler Neely
// Copyright 2014 Tyler Neely
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// Licensed under the Apache License, Version 2.0 (the "License");
...
@@ -133,21 +132,19 @@ impl<'a> Iterator for &'a mut MergeOperands {
...
@@ -133,21 +132,19 @@ impl<'a> Iterator for &'a mut MergeOperands {
fn
next
(
&
mut
self
)
->
Option
<&
'a
[
u8
]
>
{
fn
next
(
&
mut
self
)
->
Option
<&
'a
[
u8
]
>
{
match
self
.cursor
==
self
.num_operands
{
match
self
.cursor
==
self
.num_operands
{
true
=>
None
,
true
=>
None
,
false
=>
{
false
=>
unsafe
{
unsafe
{
let
base
=
self
.operands_list
as
usize
;
let
base
=
self
.operands_list
as
usize
;
let
base_len
=
self
.operands_list_len
as
usize
;
let
base_len
=
self
.operands_list_len
as
usize
;
let
spacing
=
mem
::
size_of
::
<*
const
*
const
u8
>
();
let
spacing
=
mem
::
size_of
::
<*
const
*
const
u8
>
();
let
spacing_len
=
mem
::
size_of
::
<*
const
size_t
>
();
let
spacing_len
=
mem
::
size_of
::
<*
const
size_t
>
();
let
len_ptr
=
let
len_ptr
=
(
base_len
+
(
spacing_len
*
self
.cursor
))
(
base_len
+
(
spacing_len
*
self
.cursor
))
as
*
const
size_t
;
as
*
const
size_t
;
let
len
=
*
len_ptr
as
usize
;
let
len
=
*
len_ptr
as
usize
;
let
ptr
=
base
+
(
spacing
*
self
.cursor
);
let
ptr
=
base
+
(
spacing
*
self
.cursor
);
self
.cursor
+=
1
;
self
.cursor
+=
1
;
Some
(
mem
::
transmute
(
slice
::
from_raw_parts
(
*
(
ptr
as
*
const
*
const
u8
)
Some
(
mem
::
transmute
(
slice
::
from_raw_parts
(
*
(
ptr
as
*
const
*
const
u8
)
as
*
const
u8
,
len
)))
as
*
const
u8
,
len
)))
}
},
}
}
}
}
}
...
@@ -203,9 +200,7 @@ fn mergetest() {
...
@@ -203,9 +200,7 @@ fn mergetest() {
None
=>
println!
(
"did not read valid utf-8 out of the db"
),
None
=>
println!
(
"did not read valid utf-8 out of the db"
),
}
}
}
}
Err
(
e
)
=>
{
Err
(
e
)
=>
println!
(
"error reading value"
),
println!
(
"error reading value"
)
}
_
=>
panic!
(
"value not present"
),
_
=>
panic!
(
"value not present"
),
}
}
...
...
src/rocksdb.rs
View file @
45d6436f
This diff is collapsed.
Click to expand it.
src/rocksdb_options.rs
View file @
45d6436f
//
// Copyright 2014 Tyler Neely
// Copyright 2014 Tyler Neely
//
//
// Licensed under the Apache License, Version 2.0 (the "License");
// Licensed under the Apache License, Version 2.0 (the "License");
...
@@ -139,7 +138,10 @@ impl Options {
...
@@ -139,7 +138,10 @@ impl Options {
pub
fn
add_merge_operator
<
'a
>
(
&
mut
self
,
pub
fn
add_merge_operator
<
'a
>
(
&
mut
self
,
name
:
&
str
,
name
:
&
str
,
merge_fn
:
fn
(
&
[
u8
],
Option
<&
[
u8
]
>
,
&
mut
MergeOperands
)
->
Vec
<
u8
>
)
{
merge_fn
:
fn
(
&
[
u8
],
Option
<&
[
u8
]
>
,
&
mut
MergeOperands
)
->
Vec
<
u8
>
)
{
let
cb
=
Box
::
new
(
MergeOperatorCallback
{
let
cb
=
Box
::
new
(
MergeOperatorCallback
{
name
:
CString
::
new
(
name
.as_bytes
())
.unwrap
(),
name
:
CString
::
new
(
name
.as_bytes
())
.unwrap
(),
merge_fn
:
merge_fn
,
merge_fn
:
merge_fn
,
...
@@ -192,10 +194,12 @@ impl Options {
...
@@ -192,10 +194,12 @@ impl Options {
pub
fn
set_use_fsync
(
&
mut
self
,
useit
:
bool
)
{
pub
fn
set_use_fsync
(
&
mut
self
,
useit
:
bool
)
{
unsafe
{
unsafe
{
match
useit
{
match
useit
{
true
=>
true
=>
{
rocksdb_ffi
::
rocksdb_options_set_use_fsync
(
self
.inner
,
1
),
rocksdb_ffi
::
rocksdb_options_set_use_fsync
(
self
.inner
,
1
)
false
=>
}
rocksdb_ffi
::
rocksdb_options_set_use_fsync
(
self
.inner
,
0
),
false
=>
{
rocksdb_ffi
::
rocksdb_options_set_use_fsync
(
self
.inner
,
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