Skip to content

Commit

Permalink
CHORE Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
linxGnu committed Nov 9, 2023
1 parent 3e916a2 commit f214041
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 188 deletions.
9 changes: 6 additions & 3 deletions array.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ package grocksdb
// #include "stdlib.h"
// #include "rocksdb/c.h"
import "C"

import (
"reflect"
"unsafe"
)

type charsSlice []*C.char
type sizeTSlice []C.size_t
type columnFamilySlice []*C.rocksdb_column_family_handle_t
type (
charsSlice []*C.char
sizeTSlice []C.size_t
columnFamilySlice []*C.rocksdb_column_family_handle_t
)

func (s charsSlice) c() **C.char {
sH := (*reflect.SliceHeader)(unsafe.Pointer(&s))
Expand Down
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mkdir -p $BUILD_PATH

CMAKE_REQUIRED_PARAMS="-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}"

snappy_version="1.1.9"
snappy_version="1.1.10"
cd $BUILD_PATH && wget https://github.com/google/snappy/archive/${snappy_version}.tar.gz && tar xzf ${snappy_version}.tar.gz && cd snappy-${snappy_version} && \
mkdir -p build_place && cd build_place && \
cmake $CMAKE_REQUIRED_PARAMS -DSNAPPY_BUILD_TESTS=OFF -DSNAPPY_BUILD_BENCHMARKS=OFF .. && \
Expand All @@ -18,7 +18,7 @@ cd $BUILD_PATH && wget https://github.com/google/snappy/archive/${snappy_version
export CFLAGS='-fPIC -O3 -pipe'
export CXXFLAGS='-fPIC -O3 -pipe -Wno-uninitialized'

zlib_version="1.2.13"
zlib_version="1.3"
cd $BUILD_PATH && wget https://github.com/madler/zlib/archive/v${zlib_version}.tar.gz && tar xzf v${zlib_version}.tar.gz && cd zlib-${zlib_version} && \
./configure --prefix=$INSTALL_PREFIX --static && make -j16 install && \
cd $BUILD_PATH && rm -rf *
Expand Down
6 changes: 3 additions & 3 deletions compaction_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ func registerCompactionFilter(filter CompactionFilter) int {

//export gorocksdb_compactionfilter_filter
func gorocksdb_compactionfilter_filter(idx int, cLevel C.int, cKey *C.char, cKeyLen C.size_t, cVal *C.char, cValLen C.size_t, cNewVal **C.char, cNewValLen *C.size_t, cValChanged *C.uchar) C.int {
key := charToByte(cKey, cKeyLen)
val := charToByte(cVal, cValLen)
key := refCBytes(cKey, cKeyLen)
val := refCBytes(cVal, cValLen)

remove, newVal := compactionFilters.Get(idx).(compactionFilterWrapper).filter.Filter(int(cLevel), key, val)
if remove {
return C.int(1)
} else if newVal != nil {
*cNewVal = byteToChar(newVal)
*cNewVal = refGoBytes(newVal)
*cNewValLen = C.size_t(len(newVal))
*cValChanged = C.uchar(1)
}
Expand Down
12 changes: 6 additions & 6 deletions comparator.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,22 @@ func registerComperator(cmp *Comparator) int {

//export gorocksdb_comparator_compare
func gorocksdb_comparator_compare(idx int, cKeyA *C.char, cKeyALen C.size_t, cKeyB *C.char, cKeyBLen C.size_t) C.int {
keyA := charToByte(cKeyA, cKeyALen)
keyB := charToByte(cKeyB, cKeyBLen)
keyA := refCBytes(cKeyA, cKeyALen)
keyB := refCBytes(cKeyB, cKeyBLen)
return C.int(comperators.Get(idx).(comperatorWrapper).comparator.Compare(keyA, keyB))
}

//export gorocksdb_comparator_compare_ts
func gorocksdb_comparator_compare_ts(idx int, cTsA *C.char, cTsALen C.size_t, cTsB *C.char, cTsBLen C.size_t) C.int {
tsA := charToByte(cTsA, cTsALen)
tsB := charToByte(cTsB, cTsBLen)
tsA := refCBytes(cTsA, cTsALen)
tsB := refCBytes(cTsB, cTsBLen)
return C.int(comperators.Get(idx).(comperatorWrapper).comparator.CompareTimestamp(tsA, tsB))
}

//export gorocksdb_comparator_compare_without_ts
func gorocksdb_comparator_compare_without_ts(idx int, cKeyA *C.char, cKeyALen C.size_t, cAHasTs C.uchar, cKeyB *C.char, cKeyBLen C.size_t, cBHasTs C.uchar) C.int {
keyA := charToByte(cKeyA, cKeyALen)
keyB := charToByte(cKeyB, cKeyBLen)
keyA := refCBytes(cKeyA, cKeyALen)
keyB := refCBytes(cKeyB, cKeyBLen)
keyAHasTs := charToBool(cAHasTs)
keyBHasTs := charToBool(cBHasTs)
return C.int(comperators.Get(idx).(comperatorWrapper).comparator.CompareWithoutTimestamp(keyA, keyAHasTs, keyB, keyBHasTs))
Expand Down
Loading

0 comments on commit f214041

Please sign in to comment.