Skip to content

Commit

Permalink
Tidy go mod
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindar committed Dec 17, 2022
1 parent 3e795a1 commit 4f573c5
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 27 deletions.
5 changes: 3 additions & 2 deletions collection.go
Expand Up @@ -239,7 +239,7 @@ func (c *Collection) DropTrigger(triggerName string) error {
}

// CreateIndex creates an index column with a specified name which depends on a given
// column. The index function will be applied on the values of the column whenever
// data column. The index function will be applied on the values of the column whenever
// a new row is added or updated.
func (c *Collection) CreateIndex(indexName, columnName string, fn func(r Reader) bool) error {
if fn == nil || columnName == "" || indexName == "" {
Expand Down Expand Up @@ -275,6 +275,8 @@ func (c *Collection) CreateIndex(indexName, columnName string, fn func(r Reader)
return nil
}

// CreateSortIndex creates a sorted index column with a specified name which depends
// on a given data column.
func (c *Collection) CreateSortIndex(indexName, columnName string) error {
if columnName == "" || indexName == "" {
return fmt.Errorf("column: create index must specify name & column")
Expand All @@ -295,7 +297,6 @@ func (c *Collection) CreateSortIndex(indexName, columnName string) error {
// Create and add the index column,
index := newSortIndex(indexName, columnName)
c.lock.Lock()
// index.Grow(uint32(c.opts.Capacity))
c.cols.Store(indexName, index)
c.cols.Store(columnName, column, index)
c.lock.Unlock()
Expand Down
33 changes: 16 additions & 17 deletions column_index.go
Expand Up @@ -5,6 +5,7 @@ package column

import (
"strings"

"github.com/kelindar/bitmap"
"github.com/kelindar/column/commit"

Expand Down Expand Up @@ -163,27 +164,27 @@ func (c *columnTrigger) Snapshot(chunk commit.Chunk, dst *commit.Buffer) {

// ----------------------- Sorted Index --------------------------

type SortIndexItem struct {
Key string
Value uint32
type sortIndexItem struct {
Key string
Value uint32
}

// columnSortIndex implements a constantly sorted column via BTree
type columnSortIndex struct {
btree *btree.BTreeG[SortIndexItem] // 1 constantly sorted data structure
backMap map[uint32]string // for constant key lookups
name string // The name of the target column
btree *btree.BTreeG[sortIndexItem] // 1 constantly sorted data structure
backMap map[uint32]string // for constant key lookups
name string // The name of the target column
}

// newSortIndex creates a new bitmap index column.
func newSortIndex(indexName, columnName string) *column {
byKeys := func (a, b SortIndexItem) bool {
byKeys := func(a, b sortIndexItem) bool {
return a.Key < b.Key
}
return columnFor(indexName, &columnSortIndex{
btree: btree.NewBTreeG[SortIndexItem](byKeys),
btree: btree.NewBTreeG(byKeys),
backMap: make(map[uint32]string),
name: columnName,
name: columnName,
})
}

Expand All @@ -197,7 +198,6 @@ func (c *columnSortIndex) Column() string {
return c.name
}


// Apply applies a set of operations to the column.
func (c *columnSortIndex) Apply(chunk commit.Chunk, r *commit.Reader) {

Expand All @@ -207,28 +207,27 @@ func (c *columnSortIndex) Apply(chunk commit.Chunk, r *commit.Reader) {
switch r.Type {
case commit.Put:
if delKey, exists := c.backMap[r.Index()]; exists {
c.btree.Delete(SortIndexItem{
Key: delKey,
c.btree.Delete(sortIndexItem{
Key: delKey,
Value: r.Index(),
})
}
upsertKey := strings.Clone(r.String()) // alloc required
c.backMap[r.Index()] = upsertKey
c.btree.Set(SortIndexItem{
Key: upsertKey,
c.btree.Set(sortIndexItem{
Key: upsertKey,
Value: r.Index(),
})
case commit.Delete:
delKey, _ := c.backMap[r.Index()]
c.btree.Delete(SortIndexItem{
Key: delKey,
c.btree.Delete(sortIndexItem{
Key: delKey,
Value: r.Index(),
})
}
}
}


// Value retrieves a value at a specified index.
func (c *columnSortIndex) Value(idx uint32) (v interface{}, ok bool) {
return nil, false
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Expand Up @@ -3,18 +3,17 @@ module github.com/kelindar/column
go 1.19

require (
github.com/imdario/mergo v0.3.13
github.com/kelindar/bitmap v1.4.1
github.com/kelindar/intmap v1.1.0
github.com/kelindar/iostream v1.3.0
github.com/kelindar/simd v1.1.2
github.com/kelindar/smutex v1.0.0
github.com/klauspost/compress v1.15.12
github.com/stretchr/testify v1.8.1
github.com/tidwall/btree v1.6.0
github.com/zeebo/xxh3 v1.0.2
)

require github.com/tidwall/btree v1.6.0 // indirect
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Expand Up @@ -3,7 +3,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/kelindar/async v1.0.0 h1:oJiFAt3fVB/b5zVZKPBU+pP9lR3JVyeox9pYlpdnIK8=
github.com/kelindar/async v1.0.0/go.mod h1:bJRlwaRiqdHi+4dpVDNHdwgyRyk6TxpA21fByLf7hIY=
github.com/kelindar/bitmap v1.4.1 h1:Ih0BWMYXkkZxPMU536DsQKRhdvqFl7tuNjImfLJWC6E=
Expand Down Expand Up @@ -32,8 +31,6 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/tidwall/btree v1.5.2 h1:5eA83Gfki799V3d3bJo9sWk+yL2LRoTEah3O/SA6/8w=
github.com/tidwall/btree v1.5.2/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/tidwall/btree v1.6.0 h1:LDZfKfQIBHGHWSwckhXI0RPSXzlo+KYdjK7FWSqOzzg=
github.com/tidwall/btree v1.6.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY=
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
Expand All @@ -48,6 +45,5 @@ golang.org/x/time v0.2.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion txn.go
Expand Up @@ -404,7 +404,7 @@ func (txn *Txn) Ascend(sortIndexName string, fn func(idx uint32)) error {
// For each btree key, check if the offset is still in
// the txn's index & return if true
sortIndexCol, _ := sortIndex.Column.(*columnSortIndex)
sortIndexCol.btree.Scan(func (item SortIndexItem) bool {
sortIndexCol.btree.Scan(func(item sortIndexItem) bool {
if txn.index.Contains(item.Value) {
// chunk := commit.ChunkAt(item.Value)
// lock.RLock(uint(chunk))
Expand Down

0 comments on commit 4f573c5

Please sign in to comment.