• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang btree.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/google/btree.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: newTestRangeSet

// newTestRangeSet creates a new range set that has the count number of ranges.
func newTestRangeSet(count int, t *testing.T) *testRangeSet {
	rs := &testRangeSet{replicasByKey: btree.New(64 /* degree */)}
	for i := 0; i < count; i++ {
		desc := &roachpb.RangeDescriptor{
			RangeID:  roachpb.RangeID(i),
			StartKey: roachpb.RKey(fmt.Sprintf("%03d", i)),
			EndKey:   roachpb.RKey(fmt.Sprintf("%03d", i+1)),
		}
		// Initialize the range stat so the scanner can use it.
		rng := &Replica{
			RangeID: desc.RangeID,
		}
		rng.mu.state.Stats = enginepb.MVCCStats{
			KeyBytes:  1,
			ValBytes:  2,
			KeyCount:  1,
			LiveCount: 1,
		}

		if err := rng.setDesc(desc); err != nil {
			t.Fatal(err)
		}
		if exRngItem := rs.replicasByKey.ReplaceOrInsert(rng); exRngItem != nil {
			t.Fatalf("failed to insert range %s", rng)
		}
	}
	return rs
}
开发者ID:YuleiXiao,项目名称:cockroach,代码行数:29,代码来源:scanner_test.go


示例2: Clear

// Clear clears the cache and resets the low-water mark.
func (tc *timestampCache) Clear(lowWater hlc.Timestamp) {
	tc.requests = btree.New(btreeDegree)
	tc.rCache.Clear()
	tc.wCache.Clear()
	tc.lowWater = lowWater
	tc.latest = tc.lowWater
}
开发者ID:knz,项目名称:cockroach,代码行数:8,代码来源:timestamp_cache.go


示例3: rebuild

// rebuildIndex does the work of regenerating the index
// with the given keys.
func rebuild(less LessFunction, keys <-chan string) *btree.BTree {
	tree := btree.New(2)
	for key := range keys {
		tree.ReplaceOrInsert(btreeString{s: key, l: less})
	}
	return tree
}
开发者ID:spxtr,项目名称:contrib,代码行数:9,代码来源:index.go


示例4: LoadCountries

// LoadCountries() loads the countries (as defined in the local
// countries constant) in a memory BTree
func LoadCountries() (*Countries, error) {

	r := csv.NewReader(strings.NewReader(countries_list))
	r.FieldsPerRecord = -1
	r.Comma = ';'

	t := btree.New(4)

	for {

		values, err := r.Read()
		if err == io.EOF {
			break
		}
		if err != nil {
			log_geolocip.Err(fmt.Sprintf("Countries error %v", err))
			break
		}

		// fmt.Println(len(values), values)

		// Use only lines with 2 values
		if len(values) == 2 {
			t.ReplaceOrInsert(Country{values[1], values[0]})
		}
	}

	return (*Countries)(t), nil
}
开发者ID:kirabou,项目名称:geoip,代码行数:31,代码来源:countries.go


示例5: BenchmarkSortedInsert_ReplaceOrInsert

func BenchmarkSortedInsert_ReplaceOrInsert(b *testing.B) {
	for i := 0; i < b.N; i++ {
		tree := btree.New(btreeDegree)
		for i := 0; i < len(fixture.SortedTestData); i++ {
			tree.ReplaceOrInsert(googItem(fixture.SortedTestData[i]))
		}
	}
}
开发者ID:yaojingguo,项目名称:benchmark-ordered-map,代码行数:8,代码来源:google-btree_test.go


示例6: getOrCreateRow

func (t *MockTable) getOrCreateRow(rowKey *keyPart) *btree.BTree {
	row := t.rows[rowKey.RowKey()]
	if row == nil {
		row = btree.New(2)
		t.rows[rowKey.RowKey()] = row
	}
	return row
}
开发者ID:neuralcubes,项目名称:gocassa,代码行数:8,代码来源:mock.go


示例7: getOrCreateRow

func (t *MockTable) getOrCreateRow(rowKey key) *btree.BTree {
	t.mtx.Lock()
	defer t.mtx.Unlock()
	row := t.rows[rowKey.RowKey()]
	if row == nil {
		row = btree.New(2)
		t.rows[rowKey.RowKey()] = row
	}
	return row
}
开发者ID:glycerine,项目名称:gocassa,代码行数:10,代码来源:mock.go


示例8: newEngine

func newEngine() *Engine {
	result := &Engine{
		incomingCh:  make(chan string, 10000),
		awaitCh:     make(chan bool),
		suggestions: btree.New(100),
	}
	go result.loop()
	return result

}
开发者ID:keep94,项目名称:scotty,代码行数:10,代码来源:suggest.go


示例9: LoadBlocksFile

// Read a MaxMind GeoIP Blocks file in memory, as a
// BTree of Blocks structures.
func LoadBlocksFile(filename string) (*Blocks, error) {

	file, err := os.Open(filename)
	if err != nil {
		log_geolocip.Err(fmt.Sprintf("Blocks error open file: %v", err))
		return nil, err
	}
	defer file.Close()

	t := btree.New(4)

	r := csv.NewReader(file)
	r.FieldsPerRecord = -1

	for {

		values, err := r.Read()
		if err == io.EOF {
			break
		}
		if err != nil {
			log_geolocip.Err(fmt.Sprintf("Blocks error reading file: %v", err))
			break
		}

		// Use only lines with 3 values
		if len(values) == 3 {

			low_ip, err := strconv.ParseUint(values[0], 10, 32)
			if err != nil {
				// log.Println("Line ignored, cannot read LowIP", err)
				continue
			}
			high_ip, err := strconv.ParseUint(values[1], 10, 32)
			if err != nil {
				// log.Println("Line ignored, cannot read HighIP", err)
				continue
			}
			loc_id, err := strconv.ParseUint(values[2], 10, 32)
			if err != nil {
				// log.Println("Line ignored, cannot read LocId", err)
				continue
			}

			var block = Block{uint32(low_ip), uint32(high_ip), uint32(loc_id)}
			// fmt.Println(block)
			t.ReplaceOrInsert(block)

		}
	}

	return (*Blocks)(t), nil
}
开发者ID:kirabou,项目名称:geoip,代码行数:55,代码来源:blocks.go


示例10: newTimestampCache

// newTimestampCache returns a new timestamp cache with supplied
// hybrid clock.
func newTimestampCache(clock *hlc.Clock) *timestampCache {
	tc := &timestampCache{
		rCache:                cache.NewIntervalCache(cache.Config{Policy: cache.CacheFIFO}),
		wCache:                cache.NewIntervalCache(cache.Config{Policy: cache.CacheFIFO}),
		requests:              btree.New(btreeDegree),
		evictionSizeThreshold: defaultEvictionSizeThreshold,
	}
	tc.Clear(clock)
	tc.rCache.Config.ShouldEvict = tc.shouldEvict
	tc.wCache.Config.ShouldEvict = tc.shouldEvict
	return tc
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:14,代码来源:timestamp_cache.go


示例11: MergeInto

// MergeInto merges all entries from this timestamp cache into the
// dest timestamp cache. The clear parameter, if true, copies the
// values of lowWater and latest and clears the destination cache
// before merging in the source.
func (tc *timestampCache) MergeInto(dest *timestampCache, clear bool) {
	if clear {
		dest.rCache.Clear()
		dest.wCache.Clear()
		dest.lowWater = tc.lowWater
		dest.latest = tc.latest
		dest.requests = btree.New(btreeDegree)
		dest.reqIDAlloc = 0

		// Because we just cleared the destination cache, we can directly
		// insert entries from this cache.
		hardMerge := func(srcCache, destCache *cache.IntervalCache) {
			srcCache.Do(func(k, v interface{}) {
				// Cache entries are mutable (see Add), so we give each cache its own
				// unique copy.
				entry := makeCacheEntry(*k.(*cache.IntervalKey), *v.(*cacheValue))
				destCache.AddEntry(entry)
			})
		}
		hardMerge(tc.rCache, dest.rCache)
		hardMerge(tc.wCache, dest.wCache)
	} else {
		dest.lowWater.Forward(tc.lowWater)
		dest.latest.Forward(tc.latest)

		// The cache was not cleared before, so we can't just insert entries because
		// intervals may need to be adjusted or removed to maintain the non-overlapping
		// guarantee.
		softMerge := func(srcCache *cache.IntervalCache, readTSCache bool) {
			srcCache.Do(func(k, v interface{}) {
				key, val := *k.(*cache.IntervalKey), *v.(*cacheValue)
				dest.add(roachpb.Key(key.Start), roachpb.Key(key.End), val.timestamp, val.txnID, readTSCache)
			})
		}
		softMerge(tc.rCache, true)
		softMerge(tc.wCache, false)
	}

	// Copy the requests.
	tc.requests.Ascend(func(i btree.Item) bool {
		req := *(i.(*cacheRequest))
		dest.reqIDAlloc++
		req.uniqueID = dest.reqIDAlloc
		dest.requests.ReplaceOrInsert(&req)
		dest.reqSpans += req.numSpans()
		return true
	})
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:52,代码来源:timestamp_cache.go


示例12: BenchmarkIterate

func BenchmarkIterate(b *testing.B) {
	tree := btree.New(btreeDegree)
	for i := 0; i < len(fixture.TestData); i++ {
		tree.ReplaceOrInsert(googItem(fixture.TestData[i]))
	}
	b.ResetTimer()

	for i := 0; i < b.N; i++ {

		tree.Ascend(func(i btree.Item) bool {
			_ = i.(googItem).Key
			_ = i.(googItem).Value
			return true
		})
	}
}
开发者ID:yaojingguo,项目名称:benchmark-ordered-map,代码行数:16,代码来源:google-btree_test.go


示例13: NewStaticDataSource

func NewStaticDataSource(name string, indexedCol int, data [][]driver.Value, cols []string) *StaticDataSource {

	sourceSchema := datasource.NewSourceSchema(name, sourceType)
	tbl := datasource.NewTable(name, sourceSchema)
	sourceSchema.AddTable(tbl)
	schema := datasource.NewSchema(name)
	schema.AddSourceSchema(sourceSchema)

	m := StaticDataSource{indexCol: indexedCol}
	m.tbl = tbl
	m.bt = btree.New(32)
	m.Schema = schema
	m.tbl.SetColumns(cols)
	for _, row := range data {
		m.Put(nil, nil, row)
	}
	return &m
}
开发者ID:schmichael,项目名称:qlbridge,代码行数:18,代码来源:btree.go


示例14: syncGo

func syncGo() {
	seq_next := int64(1)
	dseq := map[string]int64{}
	dlog := btree.New(8)
	cur_wchan := make(chan struct{}, 0)
	for {
		req := <-syncChan
		switch req := req.(type) {
		case syncNotifyReq:
			item_seq := dseq[req.key]
			if item_seq > 0 {
				i := dlog.Get(kdVersion{seq: item_seq})
				cur := i.(kdVersion)
				if cur.data == req.data {
					continue
				}
				dlog.Delete(kdVersion{seq: item_seq})
			}
			dseq[req.key] = seq_next
			dlog.ReplaceOrInsert(kdVersion{seq: seq_next, key: req.key, data: req.data})
			seq_next++
			close(cur_wchan)
			cur_wchan = make(chan struct{}, 0)
		case syncRefreshReq:
			update := map[string]string{}
			dlog.AscendGreaterOrEqual(kdVersion{seq: req.last_seq}, func(i btree.Item) bool {
				kd := i.(kdVersion)
				update[kd.key] = kd.data
				return true
			})
			req.rsp_ch <- syncRefreshRsp{
				seq:    seq_next,
				update: update,
				wchan:  cur_wchan,
			}
		}
	}
}
开发者ID:hnsl,项目名称:ninja,代码行数:38,代码来源:web-sync.go


示例15: closeAllUDPSession

		} else {
			u.addr.ip = make(net.IP, 4)
		}
		r.Read(u.addr.ip)
		bodylen -= uint16(len(u.addr.ip))
		binary.Read(r, binary.BigEndian, &u.addr.port)
		bodylen -= 2
		u.content = make([]byte, int(bodylen))
		r.Read(u.content)
	}
	return nil
}

var udpSessionTable = make(map[uint16]*udpSession)
var udpSessionIdSet = btree.New(4)
var cidTable = make(map[uint32]uint16)
var udpSessionMutex sync.Mutex

func closeAllUDPSession() {
	udpSessionMutex.Lock()
	defer udpSessionMutex.Unlock()
	for id, _ := range udpSessionTable {
		delete(udpSessionTable, id)
		//closeProxySession(session.session.id)
	}
	cidTable = make(map[uint32]uint16)
}

func removeUdpSession(id *udpSessionId) {
	s, exist := udpSessionTable[id.id]
开发者ID:yinqiwen,项目名称:gsnova,代码行数:30,代码来源:udpgw.go


示例16: FlushAll

func (r *MemoryBTreeDB) FlushAll() (int64, error) {
	r.data = btree.New(8)
	return 0, nil
}
开发者ID:NexwayGroup,项目名称:nx-lib,代码行数:4,代码来源:memoryBTreeDB.go


示例17: newTreeIndex

func newTreeIndex() index {
	return &treeIndex{
		tree: btree.New(32),
	}
}
开发者ID:hongchaodeng,项目名称:etcd,代码行数:5,代码来源:index.go


示例18: NewSelection

// NewSelection creates a new empty Selection
func NewSelection() *Selection {
	return &Selection{btree.New(32)}
}
开发者ID:aauren,项目名称:peco,代码行数:4,代码来源:selection.go


示例19: Reset

func (s *Selection) Reset() {
	s.mutex.Lock()
	defer s.mutex.Unlock()
	s.tree = btree.New(32)
}
开发者ID:yaoshipu,项目名称:peco,代码行数:5,代码来源:selection.go


示例20: NewGoogleBTree

func NewGoogleBTree(lesser func(l, r interface{}) bool) *GoogleBTree {
	return &GoogleBTree{
		bt:     btree.New(32),
		lesser: lesser,
	}
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:6,代码来源:google_btree.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang memory.New函数代码示例发布时间:2022-05-23
下一篇:
Golang blueprint.ModuleContext类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap