本文整理汇总了Golang中simplejsondb/core.Uint32Index类的典型用法代码示例。如果您正苦于以下问题:Golang Uint32Index类的具体用法?Golang Uint32Index怎么用?Golang Uint32Index使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Uint32Index类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Search
func Search(index core.Uint32Index, buffer dbio.DataBuffer, key, value string) ([]*core.Record, error) {
results := []*core.Record{}
index.All(func(id uint32, rowID core.RowID) {
record, err := core.NewRecordLoader(buffer).Load(id, rowID)
if err != nil {
// Ideally should recover but that means lots of stuff needs to be changed
panic(err)
}
json, err := record.ParseJSON()
if err != nil {
panic(err)
}
jsonValue, ok := json[key]
if !ok {
return
}
if jsonValue == value {
results = append(results, record)
}
})
return results, nil
}
示例2: Find
func Find(index core.Uint32Index, buffer dbio.DataBuffer, id uint32) (*core.Record, error) {
rowID, err := index.Find(id)
if err != nil {
return nil, err
}
return core.NewRecordLoader(buffer).Load(id, rowID)
}
示例3: Update
func Update(index core.Uint32Index, buffer dbio.DataBuffer, record *core.Record) error {
rowID, err := index.Find(record.ID)
if err != nil {
return err
}
allocator := core.NewRecordAllocator(buffer)
if err = allocator.Update(rowID, record); err != nil {
return err
}
return nil
}
示例4: Delete
func Delete(index core.Uint32Index, buffer dbio.DataBuffer, id uint32) error {
rowID, err := index.Find(id)
if err != nil {
return err
}
allocator := core.NewRecordAllocator(buffer)
if err := allocator.Remove(rowID); err != nil {
return err
}
return index.Delete(id)
}
示例5: assertIndexCanInsertAndFind
func assertIndexCanInsertAndFind(t *testing.T, index core.Uint32Index, key int, rowID core.RowID) (core.Uint32Key, core.RowID) {
insertOnIndex(t, index, key, rowID)
rowIDFound, err := index.Find(uint32(key))
if err != nil {
t.Fatalf("Error when trying to find rowID with key=%+v: %s", key, err)
}
if rowIDFound == (core.RowID{}) {
t.Errorf("Could not retrieve %d from index right after inserting it", key)
}
if rowIDFound != rowID {
t.Errorf("Invalid value returned from the index: %+v", rowIDFound)
}
return core.Uint32Key(key), rowID
}
示例6: Insert
func Insert(index core.Uint32Index, buffer dbio.DataBuffer, record *core.Record) error {
cb := core.NewDataBlockRepository(buffer).ControlBlock()
buffer.MarkAsDirty(cb.DataBlockID())
rowID, _ := index.Find(record.ID)
if rowID != (core.RowID{}) {
return fmt.Errorf("Key already exists: %d", record.ID)
}
allocator := core.NewRecordAllocator(buffer)
rowID, err := allocator.Add(record)
if err != nil {
return err
}
return index.Insert(record.ID, rowID)
}
示例7: assertIndexItemsAreSame
func assertIndexItemsAreSame(t *testing.T, index core.Uint32Index, rowIDs []core.RowID) {
i := 0
funcCalled := false
index.All(func(_ uint32, rowID core.RowID) {
funcCalled = true
if rowID != rowIDs[i] {
t.Errorf("Invalid value returned from the index at %d: %+v (expected %+v)", i, rowID, rowIDs[i])
}
i++
})
if i != len(rowIDs) {
t.Errorf("Did not iterate over all entries")
}
if !funcCalled && len(rowIDs) > 0 {
t.Errorf("Function passed to core.Uint32Index was not called")
}
}
示例8: assertIndexCantFindByKey
func assertIndexCantFindByKey(t *testing.T, index core.Uint32Index, key int) {
if _, err := index.Find(uint32(key)); err == nil {
t.Error("Did not remove key from index")
}
}
示例9: assertIndexCanDeleteByKey
func assertIndexCanDeleteByKey(t *testing.T, index core.Uint32Index, key int) {
index.Delete(uint32(key))
assertIndexCantFindByKey(t, index, key)
}
示例10: insertOnIndex
func insertOnIndex(t *testing.T, index core.Uint32Index, key int, rowID core.RowID) {
if err := index.Insert(uint32(key), rowID); err != nil {
t.Fatalf("Error inserting rowID with key %d: %s", key, err)
}
}