Skip to content

Commit

Permalink
remove deprecated cmp_suffix32 feature #87
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Nov 24, 2022
1 parent fa095bd commit 2cd9df4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 172 deletions.
137 changes: 0 additions & 137 deletions mdbx/cursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,143 +337,6 @@ func TestLastDup(t *testing.T) {

}

func TestDupCmpExcludeSuffix32(t *testing.T) {
hash32Bytes := FromHex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
env := setup(t)

var dbi DBI
err := env.Update(func(txn *Txn) (err error) {
dcmp := txn.GetCmpExcludeSuffix32()
dbi, err = txn.OpenDBI("testdb", Create|DupSort, nil, dcmp)
if err != nil {
return err
}

if txn.DCmp(dbi, []byte{0}, append([]byte{0}, hash32Bytes...)) != 0 {
t.Errorf("broken order")
}
if txn.DCmp(dbi, []byte{0, 0}, append([]byte{0}, hash32Bytes...)) != 1 {
t.Errorf("broken order")
}
if txn.DCmp(dbi, hash32Bytes, append([]byte{0}, hash32Bytes...)) != -1 {
t.Errorf("broken order")
}

return nil
})
if err != nil {
t.Errorf("%s", err)
return
}

err = env.Update(func(txn *Txn) (err error) {
err = txn.Put(dbi, []byte{0}, hash32Bytes, Append|AppendDup)
if err != nil {
panic(err)
}
err = txn.Put(dbi, []byte{0}, append([]byte{0}, hash32Bytes...), AppendDup)
if err != nil {
panic(err)
}
err = txn.Put(dbi, []byte{0}, append([]byte{0, 0}, hash32Bytes...), AppendDup)
if err != nil {
panic(err)
}
err = txn.Put(dbi, []byte{1}, hash32Bytes, Append|AppendDup)
if err != nil {
panic(err)
}
return err
})
if err != nil {
t.Errorf("%s", err)
}

err = env.View(func(txn *Txn) (err error) {
cur, err := txn.OpenCursor(dbi)
if err != nil {
return err
}

defer cur.Close()
k, v, err := cur.Get(nil, nil, Last)
if err != nil {
return err
}
if !bytes.Equal(k, []byte{1}) {
t.Errorf("unexpected order: %x (not %x)", k, []byte{1})
}
if !bytes.Equal(v, hash32Bytes) {
t.Errorf("unexpected order: %x (not %x)", v, hash32Bytes)
}

_, _, err = cur.Get([]byte{0}, nil, First)
if err != nil {
return err
}

_, v, err = cur.Get(nil, nil, FirstDup)
if err != nil {
return err
}
if !bytes.Equal(v, hash32Bytes) {
t.Errorf("unexpected order: %x (not %x)", v, hash32Bytes)
}

_, v, err = cur.Get(nil, nil, NextDup)
if err != nil {
return err
}
if !bytes.Equal(v, append([]byte{0}, hash32Bytes...)) {
t.Errorf("unexpected order: %x (not %x)", v, append([]byte{0}, hash32Bytes...))
}
_, v, err = cur.Get(nil, nil, LastDup)
if err != nil {
return err
}
if !bytes.Equal(v, append([]byte{0, 0}, hash32Bytes...)) {
t.Errorf("unexpected order: %x (not %x)", v, append([]byte{0, 0}, hash32Bytes...))
}

k, v, err = cur.Get(nil, nil, Next)
if err != nil {
return err
}
if !bytes.Equal(k, []byte{1}) {
t.Errorf("unexpected order: %x (not %x)", k, []byte{1})
}
if !bytes.Equal(v, hash32Bytes) {
t.Errorf("unexpected order: %x (not %x)", v, hash32Bytes)
}

k, _, err = cur.Get([]byte{0}, []byte{40}, GetBothRange)
if !IsNotFound(err) {
t.Errorf("unexpected error: %v (key %x)", err, k)
}

_, v, err = cur.Get([]byte{0}, []byte{0}, GetBothRange)
if err != nil {
return err
}
if !bytes.Equal(v, append([]byte{0}, hash32Bytes...)) {
t.Errorf("unexpected order: %x (not %x)", v, append([]byte{0}, hash32Bytes...))
}

_, v, err = cur.Get([]byte{0}, nil, SetRange)
if err != nil {
return err
}
if !bytes.Equal(v, hash32Bytes) {
t.Errorf("unexpected order: %x (not %x)", v, hash32Bytes)
}

return err
})
if err != nil {
t.Errorf("%s", err)
}
}

func TestCursor_Get_op_Set_bytesBuffer(t *testing.T) {
env := setup(t)

Expand Down
24 changes: 0 additions & 24 deletions mdbx/mdbxgo.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,30 +97,6 @@ int mdbxgo_cursor_get2(MDBX_cursor *cur, char *kdata, size_t kn, char *vdata, si
// return likely(diff_data) ? diff_data : diff_len;
//}

static int mdbxgo_dup_cmp_exclude_suffix32(const MDBX_val *a, const MDBX_val *b) {
int diff;
ssize_t len_diff;
unsigned int len;
unsigned int lenA;
unsigned int lenB;

lenA = a->iov_len >= 32 ? a->iov_len - 32 : a->iov_len;
lenB = b->iov_len >= 32 ? b->iov_len - 32 : b->iov_len;
len = lenA;
len_diff = (ssize_t) lenA - (ssize_t) lenB;
if (len_diff > 0) {
len = lenB;
len_diff = 1;
}

diff = memcmp(a->iov_base, b->iov_base, len);
return diff ? diff : len_diff<0 ? -1 : len_diff;
}

MDBX_cmp_func *mdbxgo_get_cmp_exclude_suffix32() {
return mdbxgo_dup_cmp_exclude_suffix32;
}

int mdbxgo_cmp(MDBX_txn *txn, MDBX_dbi dbi, char *adata, size_t an, char *bdata, size_t bn) {
MDBX_val a;
MDBXGO_SET_VAL(&a, an, adata);
Expand Down
3 changes: 0 additions & 3 deletions mdbx/mdbxgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ typedef struct{ const char *p; } mdbxgo_ConstCString;
int mdbxgo_reader_list(MDBX_env *env, size_t ctx);


int mdbxgo_set_dupsort_cmp_exclude_suffix32(MDBX_txn *txn, MDBX_dbi dbi);
int mdbxgo_cmp(MDBX_txn *txn, MDBX_dbi dbi, char *adata, size_t an, char *bdata, size_t bn);
int mdbxgo_dcmp(MDBX_txn *txn, MDBX_dbi dbi, char *adata, size_t an, char *bdata, size_t bn);

MDBX_cmp_func *mdbxgo_get_cmp_exclude_suffix32();

#endif
13 changes: 5 additions & 8 deletions mdbx/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,11 @@ type TxInfo struct {
}

// scan_rlt The boolean flag controls the scan of the read lock
// table to provide complete information. Such scan
// is relatively expensive and you can avoid it
// if corresponding fields are not needed.
// See description of \ref MDBX_txn_info.
//
// table to provide complete information. Such scan
// is relatively expensive and you can avoid it
// if corresponding fields are not needed.
// See description of \ref MDBX_txn_info.
func (txn *Txn) Info(scanRlt bool) (*TxInfo, error) {
var _stat C.MDBX_txn_info
ret := C.mdbx_txn_info(txn._txn, &_stat, C.bool(scanRlt))
Expand Down Expand Up @@ -632,10 +633,6 @@ type TxnOp func(txn *Txn) error

type CmpFunc *C.MDBX_cmp_func

func (txn *Txn) GetCmpExcludeSuffix32() CmpFunc {
return C.mdbxgo_get_cmp_exclude_suffix32()
}

// Cmp - this func follow bytes.Compare return style: The result will be 0 if a==b, -1 if a < b, and +1 if a > b.
func (txn *Txn) Cmp(dbi DBI, a []byte, b []byte) int {
adata, an := valBytes(a)
Expand Down

0 comments on commit 2cd9df4

Please sign in to comment.