diff --git a/fragment.go b/fragment.go index 063848e5c..a3ba53126 100644 --- a/fragment.go +++ b/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) {} diff --git a/fragment_internal_test.go b/fragment_internal_test.go index 6cd538805..c85b7e88c 100644 --- a/fragment_internal_test.go +++ b/fragment_internal_test.go @@ -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 } diff --git a/view.go b/view.go index 046a36879..e53ac8970 100644 --- a/view.go +++ b/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 }