Commit 5a23e03b authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 1a2c3afd
// Copyright (C) 2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
package blib
// map [lo,hi) Key ranges to values.
import (
"fmt"
)
const traceRangeMap = true
const debugRangeMap = true
type VALUE = interface{}
// RangedMap is Key->VALUE map with adjacent keys mapped to the same value coalesced into Ranges.
//
// Zero value represents empty map.
type RangedMap struct {
// XXX -> BTree
entryv []mapEntry // lo↑
}
type mapEntry struct {
keycov KeyRange
value VALUE
}
// Set changes m to map key k to value v.
func (m *RangedMap) Set(k Key, v VALUE) {
m.SetRange(KeyRange{Lo: k, Hi_: k}, v)
}
// Del removes key k.
func (m *RangedMap) Del(k Key) {
m.DelRange(KeyRange{Lo: k, Hi_: k})
}
// Has returns whether key k is present in the map.
func (m *RangedMap) Has(k Key) bool {
_, ok := m.Get_(k)
return ok
}
// Get returns value associated with key k.
func (m *RangedMap) Get(k Key) VALUE {
v, _ := m.Get_(k)
return v
}
// Get_ is comma-ok version of Get.
func (m *RangedMap) Get_(k Key) (VALUE, bool) {
panic("TODO") // XXX
}
// SetRange changes m to map key range r to value v.
func (m *RangedMap) SetRange(r KeyRange, v VALUE) {
panic("TODO") // XXX
}
// DelRange removes range r from the map.
func (m *RangedMap) DelRange(r KeyRange) {
panic("TODO") // XXX
}
// XXX HasRange ?
// --------
// verify checks RangedMap for internal consistency:
// - XXX
func (m *RangedMap) verify() {
// XXX
}
// Empty returns whether the map is empty.
func (m *RangedMap) Empty() bool {
return len(m.entryv) == 0
}
// XXX Equal ?
// XXX Clear ?
// XXX AllEntries ?
func (m *RangedMap) String() string {
s := "{"
for i, e := range m.entryv {
if i > 0 {
s += " "
}
s += fmt.Sprintf("%s:%v", e.keycov, e.value)
}
s += "}"
return s
}
......@@ -294,7 +294,7 @@ func (A *RangedKeySet) DifferenceInplace(B *RangedKeySet) {
// --------
// verify check RangedKeySet for internal consistency:
// verify checks RangedKeySet for internal consistency:
// - ranges must be not overlapping nor adjacent and ↑
func (S *RangedKeySet) verify() {
// TODO !debug -> return
......@@ -365,6 +365,7 @@ func (S *RangedKeySet) AllRanges() /*readonly*/[]KeyRange {
return S.rangev
}
// XXX -> ptr?
func (S RangedKeySet) String() string {
s := "{"
for i, r := range S.rangev {
......
......@@ -160,7 +160,9 @@ type _ΔTtail struct {
// set of nodes that were requested to be tracked in this tree, but for
// which vδT was not yet rebuilt
trackNew blib.PPTreeSubSet
// XXX + trackNewKeys RangedKeySet (concurrency)
// XXX + trackSetKeys RangedKeySet
}
// _ΔBroots represents roots-only part of ΔB.
......@@ -882,6 +884,8 @@ func (δBtail *ΔBtail) GetAt(root zodb.Oid, key Key, at zodb.Tid) (value Value,
rev = tail
revExact = false
// XXX need to rebuild only if key was not rebuilt yet
// XXX need to rebuild only for key, not for whole trackNew
err = δBtail.rebuild1IfNeeded(root)
if err != nil {
return value, rev, valueExact, revExact, err
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment