Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Python Rocksdb
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
Python Rocksdb
Commits
6f452968
Commit
6f452968
authored
11 years ago
by
hofmockel
Browse files
Options
Downloads
Patches
Plain Diff
PySliceTransfrom to bridge python and c++
parent
40c87ae7
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
rocksdb/_rocksdb.pyx
+60
-0
60 additions, 0 deletions
rocksdb/_rocksdb.pyx
rocksdb/interfaces.py
+19
-0
19 additions, 0 deletions
rocksdb/interfaces.py
rocksdb/slice_transform.pxd
+20
-0
20 additions, 0 deletions
rocksdb/slice_transform.pxd
with
99 additions
and
0 deletions
rocksdb/_rocksdb.pyx
+
60
−
0
View file @
6f452968
...
...
@@ -15,6 +15,7 @@ cimport options
cimport
merge_operator
cimport
filter_policy
cimport
comparator
cimport
slice_transform
cimport
cache
cimport
logger
cimport
snapshot
...
...
@@ -29,6 +30,7 @@ from interfaces import MergeOperator as IMergeOperator
from
interfaces
import
AssociativeMergeOperator
as
IAssociativeMergeOperator
from
interfaces
import
FilterPolicy
as
IFilterPolicy
from
interfaces
import
Comparator
as
IComparator
from
interfaces
import
SliceTransform
as
ISliceTransform
import
traceback
import
errors
...
...
@@ -426,7 +428,65 @@ cdef class PyLRUCache(PyCache):
LRUCache
=
PyLRUCache
###############################
### Here comes the stuff for SliceTransform
@cython.internal
cdef
class
PySliceTransform
(
object
):
cdef
slice_transform
.
SliceTransform
*
transfomer
cdef
object
ob
def
__cinit__
(
self
,
object
ob
):
if
not
isinstance
(
ob
,
ISliceTransform
):
raise
TypeError
(
"
%s is not of type %s
"
%
(
ob
,
ISliceTransform
))
self
.
ob
=
ob
self
.
transfomer
=
<
slice_transform
.
SliceTransform
*>
(
new
slice_transform
.
SliceTransformWrapper
(
bytes_to_string
(
ob
.
name
()),
<
void
*>
ob
,
slice_transform_callback
,
slice_in_domain_callback
,
slice_in_range_callback
))
def
__dealloc__
(
self
):
del
self
.
transfomer
cdef
object
get_ob
(
self
):
return
self
.
ob
cdef
slice_transform
.
SliceTransform
*
get_transformer
(
self
):
return
self
.
transfomer
cdef
Slice
slice_transform_callback
(
void
*
ctx
,
const
Slice
&
src
)
with
gil
:
cdef
size_t
offset
cdef
size_t
size
try
:
ret
=
(
<
object
>
ctx
).
transform
(
slice_to_bytes
(
src
))
offset
=
ret
[
0
]
size
=
ret
[
1
]
return
Slice
(
src
.
data
()
+
offset
,
size
)
except
Exception
as
error
:
print
error
# TODO: Use the rocksdb logger
return
src
cdef
cpp_bool
slice_in_domain_callback
(
void
*
ctx
,
const
Slice
&
src
)
with
gil
:
try
:
return
(
<
object
>
ctx
).
in_domain
(
slice_to_bytes
(
src
))
except
Exception
as
error
:
print
error
# TODO: Use the rocksdb logger
return
False
cdef
cpp_bool
slice_in_range_callback
(
void
*
ctx
,
const
Slice
&
src
)
with
gil
:
try
:
return
(
<
object
>
ctx
).
in_range
(
slice_to_bytes
(
src
))
except
Exception
as
error
:
print
error
# TODO: Use rocksdb logger
return
False
###########################################
cdef
class
CompressionType
(
object
):
no_compression
=
u
'
no_compression
'
snappy_compression
=
u
'
snappy_compression
'
...
...
This diff is collapsed.
Click to expand it.
rocksdb/interfaces.py
+
19
−
0
View file @
6f452968
...
...
@@ -56,3 +56,22 @@ class FilterPolicy:
@abstractmethod
def
key_may_match
(
self
,
key
,
filter_
):
pass
class
SliceTransform
:
__metaclass__
=
ABCMeta
@abstractmethod
def
name
(
self
):
pass
@abstractmethod
def
transform
(
self
,
src
):
pass
@abstractmethod
def
in_domain
(
self
,
src
):
pass
@abstractmethod
def
in_range
(
self
,
dst
):
pass
This diff is collapsed.
Click to expand it.
rocksdb/slice_transform.pxd
0 → 100644
+
20
−
0
View file @
6f452968
from
slice_
cimport
Slice
from
libcpp.string
cimport
string
from
libcpp
cimport
bool
as
cpp_bool
cdef
extern
from
"
rocksdb/slice_transform.h
"
namespace
"
rocksdb
"
:
cdef
cppclass
SliceTransform
:
pass
ctypedef
Slice
(
*
transform_func
)(
void
*
,
const
Slice
&
)
ctypedef
cpp_bool
(
*
in_domain_func
)(
void
*
,
const
Slice
&
)
ctypedef
cpp_bool
(
*
in_range_func
)(
void
*
,
const
Slice
&
)
cdef
extern
from
"
cpp/slice_transform_wrapper.hpp
"
namespace
"
py_rocks
"
:
cdef
cppclass
SliceTransformWrapper
:
SliceTransformWrapper
(
string
name
,
void
*
,
transform_func
,
in_domain_func
,
in_range_func
)
nogil
except
+
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment