mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
swap out mapVector for rowsVector in mutex fields
This commit is contained in:
parent
a07ed360ab
commit
06f5d04f1c
3 changed files with 29 additions and 2 deletions
27
fragment.go
27
fragment.go
|
|
@ -2058,3 +2058,30 @@ func (m *mapVector) Set(colID, rowID uint64) {
|
|||
defer m.mu.Unlock()
|
||||
m.m[colID] = rowID
|
||||
}
|
||||
|
||||
// rowsVector implements the vector interface by looking
|
||||
// at row data as needed.
|
||||
type rowsVector struct {
|
||||
f *fragment
|
||||
}
|
||||
|
||||
// newRowsVector returns a rowsVector for a given fragment.
|
||||
func newRowsVector(f *fragment) *rowsVector {
|
||||
return &rowsVector{
|
||||
f: f,
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns the rowID associated to the given colID.
|
||||
// Additionaly, it returns true if a value was found,
|
||||
// otherwise it returns false.
|
||||
func (v *rowsVector) Get(colID uint64) (uint64, bool) {
|
||||
rows := v.f.rowsForColumn(colID)
|
||||
if len(rows) == 1 {
|
||||
return rows[0], true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
// Set is not used for rowsVector.
|
||||
func (v *rowsVector) Set(colID, rowID uint64) {}
|
||||
|
|
|
|||
|
|
@ -1295,7 +1295,7 @@ func mustOpenFragment(index, field, view string, shard uint64, cacheType string)
|
|||
// mustOpenMutexFragment returns a new instance of Fragment for a mutex field.
|
||||
func mustOpenMutexFragment(index, field, view string, shard uint64, cacheType string) *fragment {
|
||||
frag := mustOpenFragment(index, field, view, shard, cacheType)
|
||||
frag.mutexVector = newMapVector()
|
||||
frag.mutexVector = newRowsVector(frag)
|
||||
return frag
|
||||
}
|
||||
|
||||
|
|
|
|||
2
view.go
2
view.go
|
|
@ -255,7 +255,7 @@ func (v *view) newFragment(path string, shard uint64) *fragment {
|
|||
frag.Logger = v.logger
|
||||
frag.stats = v.stats.WithTags(fmt.Sprintf("shard:%d", shard))
|
||||
if v.fieldType == FieldTypeMutex {
|
||||
frag.mutexVector = newMapVector()
|
||||
frag.mutexVector = newRowsVector(frag)
|
||||
}
|
||||
return frag
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue