MCPcopy
hub / github.com/cayleygraph/cayley / Set

Method Set

graph/memstore/keys.go:580–631  ·  view source on GitHub ↗

Set sets the value associated with k.

(k int64, v *primitive)

Source from the content-addressed store, hash-verified

578
579// Set sets the value associated with k.
580func (t *Tree) Set(k int64, v *primitive) {
581 //dbg("--- PRE Set(%v, %v)\n%s", k, v, t.dump())
582 //defer func() {
583 // dbg("--- POST\n%s\n====\n", t.dump())
584 //}()
585
586 pi := -1
587 var p *x
588 q := t.r
589 if q == nil {
590 z := t.insert(btDPool.Get().(*d), 0, k, v)
591 t.r, t.first, t.last = z, z, z
592 return
593 }
594
595 for {
596 i, ok := t.find(q, k)
597 if ok {
598 switch x := q.(type) {
599 case *x:
600 if x.c > 2*kx {
601 x, i = t.splitX(p, x, pi, i)
602 }
603 pi = i + 1
604 p = x
605 q = x.x[i+1].ch
606 continue
607 case *d:
608 x.d[i].v = v
609 }
610 return
611 }
612
613 switch x := q.(type) {
614 case *x:
615 if x.c > 2*kx {
616 x, i = t.splitX(p, x, pi, i)
617 }
618 pi = i
619 p = x
620 q = x.x[i].ch
621 case *d:
622 switch {
623 case x.c < 2*kd:
624 t.insert(x, i, k, v)
625 default:
626 t.overflow(p, x, pi, i, k, v)
627 }
628 return
629 }
630 }
631}
632
633// Put combines Get and Set in a more efficient way where the tree is walked
634// only once. The upd(ater) receives (old-value, true) if a KV pair for k

Callers 14

flushMapBucketMethod · 0.45
primitiveToQuadMethod · 0.45
benchmarkSetSeqFunction · 0.45
benchmarkGetSeqFunction · 0.45
benchmarkSetRndFunction · 0.45
benchmarkGetRndFunction · 0.45
benchmarkDelSeqFunction · 0.45
benchmarkDelRndFunction · 0.45
benchmarkSeekSeqFunction · 0.45
benchmarkSeekRndFunction · 0.45
benchmarkNextFunction · 0.45
benchmarkPrevFunction · 0.45

Calls 5

insertMethod · 0.95
findMethod · 0.95
splitXMethod · 0.95
overflowMethod · 0.95
GetMethod · 0.45

Tested by 10

benchmarkSetSeqFunction · 0.36
benchmarkGetSeqFunction · 0.36
benchmarkSetRndFunction · 0.36
benchmarkGetRndFunction · 0.36
benchmarkDelSeqFunction · 0.36
benchmarkDelRndFunction · 0.36
benchmarkSeekSeqFunction · 0.36
benchmarkSeekRndFunction · 0.36
benchmarkNextFunction · 0.36
benchmarkPrevFunction · 0.36