当前位置: 首页>>代码示例>>Golang>>正文


Golang core.Uint32Index类代码示例

本文整理汇总了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
}
开发者ID:fgrehm,项目名称:pucrs-simple-json-db,代码行数:25,代码来源:search.go

示例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)
}
开发者ID:fgrehm,项目名称:pucrs-simple-json-db,代码行数:8,代码来源:find.go

示例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
}
开发者ID:fgrehm,项目名称:pucrs-simple-json-db,代码行数:13,代码来源:update.go

示例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)
}
开发者ID:fgrehm,项目名称:pucrs-simple-json-db,代码行数:13,代码来源:delete.go

示例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
}
开发者ID:fgrehm,项目名称:pucrs-simple-json-db,代码行数:14,代码来源:uint32_index_test.go

示例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)
}
开发者ID:fgrehm,项目名称:pucrs-simple-json-db,代码行数:17,代码来源:insert.go

示例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")
	}
}
开发者ID:fgrehm,项目名称:pucrs-simple-json-db,代码行数:17,代码来源:uint32_index_test.go

示例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")
	}
}
开发者ID:fgrehm,项目名称:pucrs-simple-json-db,代码行数:5,代码来源:uint32_index_test.go

示例9: assertIndexCanDeleteByKey

func assertIndexCanDeleteByKey(t *testing.T, index core.Uint32Index, key int) {
	index.Delete(uint32(key))
	assertIndexCantFindByKey(t, index, key)
}
开发者ID:fgrehm,项目名称:pucrs-simple-json-db,代码行数:4,代码来源:uint32_index_test.go

示例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)
	}
}
开发者ID:fgrehm,项目名称:pucrs-simple-json-db,代码行数:5,代码来源:uint32_index_test.go


注:本文中的simplejsondb/core.Uint32Index类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。