diff --git a/mdbx/cursor_test.go b/mdbx/cursor_test.go index 8a57373..a925570 100644 --- a/mdbx/cursor_test.go +++ b/mdbx/cursor_test.go @@ -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) diff --git a/mdbx/mdbxgo.c b/mdbx/mdbxgo.c index 826f5f2..f949d03 100644 --- a/mdbx/mdbxgo.c +++ b/mdbx/mdbxgo.c @@ -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); diff --git a/mdbx/mdbxgo.h b/mdbx/mdbxgo.h index 15079b6..8507421 100644 --- a/mdbx/mdbxgo.h +++ b/mdbx/mdbxgo.h @@ -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 diff --git a/mdbx/txn.go b/mdbx/txn.go index d15a5e7..b063821 100644 --- a/mdbx/txn.go +++ b/mdbx/txn.go @@ -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)) @@ -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)