本文整理汇总了Golang中github.com/petar/GoLLRB/llrb.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: record
func (s marketStore) record(m emdn.Transaction) {
k := m.Item
// Demand
tree, ok := s.itemDemand[k]
if !ok {
tree = llrb.New()
s.itemDemand[k] = tree
}
tree.ReplaceOrInsert(demtrans(m))
for tree.Len() > maxItems {
tree.DeleteMin()
}
stationPriceUpdate(s.stationDemand, m.Station, k, m.SellPrice)
// Supply
tree, ok = s.itemSupply[k]
if !ok {
tree = llrb.New()
s.itemSupply[k] = tree
}
if m.BuyPrice == 0 {
m.BuyPrice = math.MaxInt64
}
tree.ReplaceOrInsert(suptrans(m))
for tree.Len() > maxItems {
tree.DeleteMax()
}
stationPriceUpdate(s.stationSupply, m.Station, k, m.BuyPrice)
}
开发者ID:nictuku,项目名称:eliteprofit,代码行数:29,代码来源:main.go
示例2: InitCache
func InitCache() *MyError.MyError {
once.Do(func() {
DomainRRCache = &DomainRRTree{
LLRB: llrb.New(),
RWMutex: &sync.RWMutex{},
}
DomainSOACache = &DomainSOATree{
LLRB: llrb.New(),
RWMutex: &sync.RWMutex{},
}
})
return nil
}
开发者ID:chunshengster,项目名称:httpDispatcher,代码行数:13,代码来源:domain.go
示例3: newShardedCache
func newShardedCache(n int, de time.Duration) *shardedCache {
max := big.NewInt(0).SetUint64(uint64(math.MaxUint32))
rnd, err := rand.Int(rand.Reader, max)
var seed uint32
if err != nil {
os.Stderr.Write([]byte("WARNING: go-cache's newShardedCache failed to read from the system CSPRNG (/dev/urandom or equivalent.) Your system's security may be compromised. Continuing with an insecure seed.\n"))
seed = insecurerand.Uint32()
} else {
seed = uint32(rnd.Uint64())
}
sc := &shardedCache{
seed: seed,
m: uint32(n),
cs: make([]*cache, n),
}
for i := 0; i < n; i++ {
c := &cache{
defaultExpiration: de,
items: map[string]Item{},
sortedItems: llrb.New(),
}
sc.cs[i] = c
}
return sc
}
开发者ID:beppeben,项目名称:go-cache,代码行数:25,代码来源:sharded.go
示例4: NewEnvironment
// NewEnvironment constructs an Environment with the given parent to provide a
// fallback for finding variables. The parent may be nil.
func NewEnvironment(parent Environment) Environment {
e := new(environment)
e.writable = true
e.vars = llrb.New()
e.parent = parent
return e
}
开发者ID:nlfiedler,项目名称:bakeneko,代码行数:9,代码来源:interpreter.go
示例5: NewTaskQueue
// Returns a new task queue.
// The user could submit new task through channel ch.
func NewTaskQueue(ch <-chan Task) *TaskQueue {
ret := new(TaskQueue)
ret.tree = llrb.New(taskBefore)
ret.ch = ch
ret.waitTime = maxTime
return ret
}
开发者ID:monnand,项目名称:gotaskqueue,代码行数:9,代码来源:taskqueue.go
示例6: SearchAddTerm
// Add a term that can be searched on (append or create to an existing term)
func (rfs *RootFileSystem) SearchAddTerm(area string, term string, path string, version string) error {
searchIndex := rfs.ChangeCache.GetSearchIndex()
treeNode, ok := searchIndex.Terms[area]
var searchTree *SearchTree = &SearchTree{}
var err error
if !ok {
// Create a node for this tree
treeNode = rfs.BlockHandler.GetFreeBlockNode(SEARCHTREE)
searchIndex.Terms[area] = treeNode
searchTree.Tree = llrb.New()
searchTree.Node = treeNode
// Need to save the searchTree back
rfs.ChangeCache.SaveSearchIndex(searchIndex)
} else {
searchTree, err = rfs.ChangeCache.GetSearchTree(treeNode)
if err != nil {
return err
}
}
// Now we have a search tree, add the term
var searchItem = SearchEntry{term, nil}
existingValue := searchTree.Tree.Get(searchItem)
var pointValue SearchEntry
if existingValue != nil {
pointValue = existingValue.(SearchEntry)
} else {
pointValue = SearchEntry{term, make([]Entry, 0)}
}
entry := Entry{path, version}
pointValue.Matches = append(pointValue.Matches, entry)
searchTree.Tree.ReplaceOrInsert(pointValue)
// And save this searchTree back
rfs.ChangeCache.SaveSearchTree(searchTree)
return nil
}
开发者ID:amkimian,项目名称:pmfs,代码行数:36,代码来源:search.go
示例7: rebuild
// rebuildIndex does the work of regenerating the index
// with the given keys.
func rebuild(less llrb.LessFunc, keys <-chan string) *llrb.Tree {
tree := llrb.New(less)
for key := range keys {
tree.ReplaceOrInsert(key)
}
return tree
}
开发者ID:goodsign,项目名称:diskv,代码行数:9,代码来源:index.go
示例8: GetOrCreate
func (tdi *TripleDirectionIndex) GetOrCreate(d graph.Direction, id int64) *llrb.LLRB {
directionIndex := tdi.GetForDir(d)
if _, ok := directionIndex[id]; !ok {
directionIndex[id] = llrb.New()
}
return directionIndex[id]
}
开发者ID:ZSIT,项目名称:cayley,代码行数:7,代码来源:triplestore.go
示例9: insert
func (this *Trellis) insert(t int, s *Bigram, sa *Bigram, kb int, p float64) {
i, ok := this.trl[t].Get(s)
if !ok {
TRACE(4, " Inserting. Is a new element, init list.", MOD_HMM)
m := llrb.New()
m.InsertNoReplace(NewElement(sa, kb, p))
this.trl[t].Insert(s, m)
} else {
TRACE(4, " Inserting. Not a new element, add. List size="+strconv.Itoa(i.(*llrb.LLRB).Len())+"/"+strconv.Itoa(this.kbest), MOD_HMM)
j := i.(*llrb.LLRB).Min()
if i.(*llrb.LLRB).Len() == this.kbest && p < j.(*Element).prob {
TRACE(4, " Not worth inserting", MOD_HMM)
return
}
i.(*llrb.LLRB).InsertNoReplace(NewElement(sa, kb, p))
if i.(*llrb.LLRB).Len() > this.kbest {
i.(*llrb.LLRB).Delete(i.(*llrb.LLRB).Min())
TRACE(4, " list too long. Last erased", MOD_HMM)
}
}
i, ok = this.trl[t].Get(s)
if ok && i.(*llrb.LLRB).Len() > 0 {
TRACE(4, "MAX:"+strconv.FormatFloat(i.(*llrb.LLRB).Max().(*Element).prob, 'f', -1, 64)+" MIN:"+strconv.FormatFloat(i.(*llrb.LLRB).Min().(*Element).prob, 'f', -1, 64), MOD_HMM)
}
}
开发者ID:payfriendz,项目名称:go-freeling,代码行数:27,代码来源:hmm.go
示例10: NewRegionCache
// NewRegionCache creates a RegionCache.
func NewRegionCache(pdClient pd.Client) *RegionCache {
return &RegionCache{
pdClient: pdClient,
regions: make(map[RegionVerID]*Region),
sorted: llrb.New(),
}
}
开发者ID:anywhy,项目名称:tidb,代码行数:8,代码来源:region_cache.go
示例11: rebuild
// rebuildIndex does the work of regenerating the index
// with the given keys.
func rebuild(less LessFunction, keys <-chan string) *llrb.LLRB {
tree := llrb.New()
for key := range keys {
tree.ReplaceOrInsert(llrbString{s: key, l: less})
}
return tree
}
开发者ID:Richardphp,项目名称:noms,代码行数:9,代码来源:index.go
示例12: NewQTask
func NewQTask() *QTask {
return &QTask{
tree: llrb.New(),
qchan: make(chan Task, 30),
waitTime: maxTime,
mTask: make(map[string]Task),
}
}
开发者ID:ShinichR,项目名称:goQTask,代码行数:8,代码来源:goQTask.go
示例13: NewRegionCache
// NewRegionCache creates a RegionCache.
func NewRegionCache(pdClient pd.Client) *RegionCache {
c := &RegionCache{
pdClient: pdClient,
}
c.mu.regions = make(map[RegionVerID]*Region)
c.mu.sorted = llrb.New()
return c
}
开发者ID:jmptrader,项目名称:tidb,代码行数:9,代码来源:region_cache.go
示例14: BenchmarkSortedInsert_InsertNoReplace
func BenchmarkSortedInsert_InsertNoReplace(b *testing.B) {
for i := 0; i < b.N; i++ {
tree := llrb.New()
for i := 0; i < len(fixture.SortedTestData); i++ {
tree.InsertNoReplace(llrbItem(fixture.SortedTestData[i]))
}
}
}
开发者ID:xwb1989,项目名称:benchmark-ordered-map,代码行数:8,代码来源:petar-GoLLRB_test.go
示例15: BenchmarkInsert
func BenchmarkInsert(b *testing.B) {
for i := 0; i < b.N; i++ {
tree := llrb.New()
for i := 0; i < len(fixture.TestData); i++ {
tree.ReplaceOrInsert(llrbItem(fixture.TestData[i]))
}
}
}
开发者ID:xwb1989,项目名称:benchmark-ordered-map,代码行数:8,代码来源:petar-GoLLRB_test.go
示例16: newTreeBasedConnMap
func newTreeBasedConnMap(maxNrConn, maxNrUsers, maxNrConnsPerUser int) connMap {
ret := new(treeBasedConnMap)
ret.tree = llrb.New()
ret.maxNrConn = maxNrConn
ret.maxNrUsers = maxNrUsers
ret.maxNrConnsPerUser = maxNrConnsPerUser
return ret
}
开发者ID:uniqush,项目名称:uniqush-conn,代码行数:8,代码来源:connmap.go
示例17: main
func main() {
tree := llrb.New()
tree.ReplaceOrInsert(llrb.Int(1))
tree.ReplaceOrInsert(llrb.Int(2))
tree.ReplaceOrInsert(llrb.Int(3))
tree.ReplaceOrInsert(llrb.Int(4))
tree.DeleteMin()
tree.Delete(llrb.Int(4))
tree.AscendGreaterOrEqual(tree.Min(), Print)
}
开发者ID:johncylee,项目名称:GoLLRB,代码行数:10,代码来源:ex1.go
示例18: Insert
func (this *Set) Insert(item interface{}) {
bin := this.bins[this.hasher(item)]
if bin == nil {
bin = llrb.New(llrb.LessFunc(this.lesser))
this.bins[this.hasher(item)] = bin
}
if bin.ReplaceOrInsert(item) == nil {
this.count++
}
}
开发者ID:qicongchen,项目名称:gohash,代码行数:10,代码来源:set.go
示例19: NewRestrictedEnvironment
// NewRestrictedEnvironment constructs an Environment with the given set of
// mappings. The environment cannot be modified.
func NewRestrictedEnvironment(parent Environment, mapping map[Symbol]interface{}) Environment {
e := new(environment)
e.writable = false
e.vars = llrb.New()
for sym, val := range mapping {
item := newEnvItem(sym, val)
e.vars.ReplaceOrInsert(item)
}
e.parent = parent
return e
}
开发者ID:nlfiedler,项目名称:bakeneko,代码行数:13,代码来源:interpreter.go
示例20: CloseAll
// There's no way back!
func (self *treeBasedConnMap) CloseAll() {
self.lock.Lock()
var nilcs *connSet
self.tree.AscendGreaterOrEqual(nilcs, func(i llrb.Item) bool {
if cs, ok := i.(*connSet); ok {
cs.CloseAll()
}
return true
})
self.tree = llrb.New()
}
开发者ID:uniqush,项目名称:uniqush-conn,代码行数:12,代码来源:connmap.go
注:本文中的github.com/petar/GoLLRB/llrb.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论