Navigation Menu

Skip to content

Commit

Permalink
Remove bytesutil package
Browse files Browse the repository at this point in the history
  • Loading branch information
asdine committed Jul 27, 2020
1 parent 7bbbeee commit 15c1b4b
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 213 deletions.
10 changes: 4 additions & 6 deletions document/compare.go
Expand Up @@ -4,8 +4,6 @@ import (
"bytes"
"errors"
"fmt"

"github.com/genjidb/genji/pkg/bytesutil"
)

type operator uint8
Expand Down Expand Up @@ -163,13 +161,13 @@ func compareBytes(op operator, l, r Value) (bool, error) {
case operatorEq:
ok = bytes.Equal(l.V.([]byte), r.V.([]byte))
case operatorGt:
ok = bytesutil.CompareBytes(l.V.([]byte), r.V.([]byte)) > 0
ok = bytes.Compare(l.V.([]byte), r.V.([]byte)) > 0
case operatorGte:
ok = bytesutil.CompareBytes(l.V.([]byte), r.V.([]byte)) >= 0
ok = bytes.Compare(l.V.([]byte), r.V.([]byte)) >= 0
case operatorLt:
ok = bytesutil.CompareBytes(l.V.([]byte), r.V.([]byte)) < 0
ok = bytes.Compare(l.V.([]byte), r.V.([]byte)) < 0
case operatorLte:
ok = bytesutil.CompareBytes(l.V.([]byte), r.V.([]byte)) <= 0
ok = bytes.Compare(l.V.([]byte), r.V.([]byte)) <= 0
}

return ok, nil
Expand Down
4 changes: 2 additions & 2 deletions document/encoding/encoding_test.go
@@ -1,9 +1,9 @@
package encoding

import (
"bytes"
"testing"

"github.com/genjidb/genji/pkg/bytesutil"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -70,7 +70,7 @@ func TestOrdering(t *testing.T) {
continue
}

require.Equal(t, -1, bytesutil.CompareBytes(prev, cur))
require.Equal(t, -1, bytes.Compare(prev, cur))
prev = cur
}
})
Expand Down
4 changes: 1 addition & 3 deletions document/json.go
Expand Up @@ -10,8 +10,6 @@ import (
"io"
"strconv"
"strings"

"github.com/genjidb/genji/pkg/bytesutil"
)

// NewFromJSON creates a document from a JSON object.
Expand Down Expand Up @@ -419,7 +417,7 @@ func (v Value) Compare(u Value) int {
if (v.Type == TextValue || v.Type == BlobValue) && (u.Type == TextValue || u.Type == BlobValue) {
bv, _ := v.ConvertToBytes()
bu, _ := u.ConvertToBytes()
return bytesutil.CompareBytes(bv, bu)
return bytes.Compare(bv, bu)
}

// if all else fails, compare string representation of values
Expand Down
5 changes: 2 additions & 3 deletions document/value.go
@@ -1,12 +1,11 @@
package document

import (
"bytes"
"errors"
"fmt"
"math"
"time"

"github.com/genjidb/genji/pkg/bytesutil"
)

var (
Expand Down Expand Up @@ -433,7 +432,7 @@ func (v Value) IsZeroValue() (bool, error) {
case DurationValue:
return v.V == durationZeroValue.V, nil
case BlobValue, TextValue:
return bytesutil.CompareBytes(v.V.([]byte), blobZeroValue.V.([]byte)) == 0, nil
return bytes.Compare(v.V.([]byte), blobZeroValue.V.([]byte)) == 0, nil
case ArrayValue:
// The zero value of an array is an empty array.
// Thus, if GetByIndex(0) returns the ErrValueNotFound
Expand Down
5 changes: 3 additions & 2 deletions engine/boltengine/store.go
@@ -1,8 +1,9 @@
package boltengine

import (
"bytes"

"github.com/genjidb/genji/engine"
"github.com/genjidb/genji/pkg/bytesutil"
bolt "go.etcd.io/bbolt"
)

Expand Down Expand Up @@ -88,7 +89,7 @@ func (it *iterator) Seek(pivot []byte) {

it.item.k, it.item.v = it.c.Seek(pivot)
if it.item.k != nil {
for bytesutil.CompareBytes(it.item.k, pivot) > 0 {
for bytes.Compare(it.item.k, pivot) > 0 {
it.item.k, it.item.v = it.c.Prev()
}
}
Expand Down
13 changes: 0 additions & 13 deletions pkg/bytesutil/bytesutil.go

This file was deleted.

146 changes: 0 additions & 146 deletions pkg/bytesutil/bytesutil_test.go

This file was deleted.

29 changes: 0 additions & 29 deletions pkg/bytesutil/bytesutil_tinygo.go

This file was deleted.

6 changes: 3 additions & 3 deletions sql/planner/sort.go
@@ -1,14 +1,14 @@
package planner

import (
"bytes"
"container/heap"
"fmt"

"github.com/genjidb/genji/database"
"github.com/genjidb/genji/document"
"github.com/genjidb/genji/document/encoding/msgpack"
"github.com/genjidb/genji/index"
"github.com/genjidb/genji/pkg/bytesutil"
"github.com/genjidb/genji/sql/query/expr"
"github.com/genjidb/genji/sql/scanner"
)
Expand Down Expand Up @@ -151,7 +151,7 @@ type heapNode struct {
type minHeap []heapNode

func (h minHeap) Len() int { return len(h) }
func (h minHeap) Less(i, j int) bool { return bytesutil.CompareBytes(h[i].value, h[j].value) < 0 }
func (h minHeap) Less(i, j int) bool { return bytes.Compare(h[i].value, h[j].value) < 0 }
func (h minHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }

func (h *minHeap) Push(x interface{}) {
Expand All @@ -171,5 +171,5 @@ type maxHeap struct {
}

func (h maxHeap) Less(i, j int) bool {
return bytesutil.CompareBytes(h.minHeap[i].value, h.minHeap[j].value) > 0
return bytes.Compare(h.minHeap[i].value, h.minHeap[j].value) > 0
}
5 changes: 2 additions & 3 deletions sql/query/expr/comparison.go
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/genjidb/genji/document/encoding/msgpack"
"github.com/genjidb/genji/engine"
"github.com/genjidb/genji/index"
"github.com/genjidb/genji/pkg/bytesutil"
"github.com/genjidb/genji/sql/scanner"
)

Expand Down Expand Up @@ -291,7 +290,7 @@ func (op ltOp) IteratePK(tb *database.Table, v document.Value, pkType document.V
if err != nil {
return err
}
if bytesutil.CompareBytes(data, d) <= 0 {
if bytes.Compare(data, d) <= 0 {
break
}

Expand Down Expand Up @@ -364,7 +363,7 @@ func (op lteOp) IteratePK(tb *database.Table, v document.Value, pkType document.
if err != nil {
return err
}
if bytesutil.CompareBytes(data, d) < 0 {
if bytes.Compare(data, d) < 0 {
break
}

Expand Down
6 changes: 3 additions & 3 deletions sql/query/plan.go
@@ -1,6 +1,7 @@
package query

import (
"bytes"
"container/heap"
"errors"

Expand All @@ -9,7 +10,6 @@ import (
"github.com/genjidb/genji/document/encoding/msgpack"
"github.com/genjidb/genji/engine"
"github.com/genjidb/genji/index"
"github.com/genjidb/genji/pkg/bytesutil"
"github.com/genjidb/genji/sql/query/expr"
"github.com/genjidb/genji/sql/scanner"
)
Expand Down Expand Up @@ -483,7 +483,7 @@ type heapNode struct {
type minHeap []heapNode

func (h minHeap) Len() int { return len(h) }
func (h minHeap) Less(i, j int) bool { return bytesutil.CompareBytes(h[i].value, h[j].value) < 0 }
func (h minHeap) Less(i, j int) bool { return bytes.Compare(h[i].value, h[j].value) < 0 }
func (h minHeap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }

func (h *minHeap) Push(x interface{}) {
Expand All @@ -503,5 +503,5 @@ type maxHeap struct {
}

func (h maxHeap) Less(i, j int) bool {
return bytesutil.CompareBytes(h.minHeap[i].value, h.minHeap[j].value) > 0
return bytes.Compare(h.minHeap[i].value, h.minHeap[j].value) > 0
}

0 comments on commit 15c1b4b

Please sign in to comment.