JS: Rename RefValue to Ref

This commit is contained in:
Erik Arvidsson
2016-05-20 19:11:09 -07:00
parent 7d8eea4a07
commit 3ae55e01ec
30 changed files with 141 additions and 141 deletions
+2 -2
View File
@@ -27,7 +27,7 @@ import {
valueType,
} from './type.js';
import {equals} from './compare.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
suite('validate type', () => {
@@ -234,7 +234,7 @@ suite('validate type', () => {
const c2 = newStruct('Commit', {
value: 2,
parents: new Set([new RefValue(c1)]),
parents: new Set([new Ref(c1)]),
});
assertSubtype(t11, c2);
+2 -2
View File
@@ -9,7 +9,7 @@ import {blobType} from './type.js';
import {MetaTuple, newIndexedMetaSequenceChunkFn, newIndexedMetaSequenceBoundaryChecker,} from
'./meta-sequence.js';
import BuzHashBoundaryChecker from './buzhash-boundary-checker.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import SequenceChunker from './sequence-chunker.js';
import type {BoundaryChecker, makeChunkFn} from './sequence-chunker.js';
import {Kind} from './noms-kind.js';
@@ -85,7 +85,7 @@ function newBlobLeafChunkFn(vr: ?ValueReader = null): makeChunkFn {
return (items: Array<number>) => {
const blobLeaf = new BlobLeafSequence(vr, new Uint8Array(items));
const blob = newBlobFromSequence(blobLeaf);
const mt = new MetaTuple(new RefValue(blob), items.length, items.length, blob);
const mt = new MetaTuple(new Ref(blob), items.length, items.length, blob);
return [mt, blob];
};
}
+2 -2
View File
@@ -1,6 +1,6 @@
// @flow
import RefValue from './ref-value.js';
import Ref from './ref.js';
import type Sequence from './sequence.js'; // eslint-disable-line no-unused-vars
import type {Type} from './type.js';
import {ValueBase} from './value.js';
@@ -21,7 +21,7 @@ export class Collection<S: Sequence> extends ValueBase {
return !this.sequence.isMeta && this.sequence.items.length === 0;
}
get chunks(): Array<RefValue> {
get chunks(): Array<Ref> {
return this.sequence.chunks;
}
}
+5 -5
View File
@@ -4,12 +4,12 @@ import {invariant} from './assert.js';
import {getDatasTypes} from './database.js';
import Struct from './struct.js';
import type Value from './value.js';
import type RefValue from './ref-value.js';
import type Ref from './ref.js';
import Set from './set.js';
export default class Commit<T: Value> extends Struct {
constructor(value: T, parents: Set<RefValue<Commit>> = new Set()) {
constructor(value: T, parents: Set<Ref<Commit>> = new Set()) {
const {commitType} = getDatasTypes();
super(commitType, {value, parents});
}
@@ -24,14 +24,14 @@ export default class Commit<T: Value> extends Struct {
return new Commit(value, this.parents);
}
get parents(): Set<RefValue<Commit>> {
get parents(): Set<Ref<Commit>> {
// $FlowIssue: _data is private.
const parents: Set<RefValue<Commit>> = this._data.parents;
const parents: Set<Ref<Commit>> = this._data.parents;
invariant(parents instanceof Set);
return parents;
}
setParents(parents: Set<RefValue<Commit>>): Commit<T> {
setParents(parents: Set<Ref<Commit>>): Commit<T> {
return new Commit(this.value, parents);
}
}
+4 -4
View File
@@ -195,7 +195,7 @@ suite('Database', () => {
const s1 = new NomsSet([v1, v2]);
assert.strictEqual(1, ds.writeValue(s1).height);
// Set<RefValue<String>>.
// Set<Ref<String>>.
const s2 = new NomsSet([ds.writeValue(v1), ds.writeValue(v2)]);
assert.strictEqual(2, ds.writeValue(s2).height);
@@ -206,16 +206,16 @@ suite('Database', () => {
const l1 = new List([s1, s3]);
assert.strictEqual(1, ds.writeValue(l1).height);
// List<RefValue<Set<String>>.
// List<Ref<Set<String>>.
const l2 = new List([ds.writeValue(s1), ds.writeValue(s3)]);
assert.strictEqual(2, ds.writeValue(l2).height);
// List<RefValue<Set<RefValue<String>>>.
// List<Ref<Set<Ref<String>>>.
const s4 = new NomsSet([ds.writeValue(v3), ds.writeValue(v4)]);
const l3 = new List([ds.writeValue(s4)]);
assert.strictEqual(3, ds.writeValue(l3).height);
// List<Set<String> | RefValue<Set<String>>>.
// List<Set<String> | Ref<Set<String>>>.
const l4 = new List([s1, ds.writeValue(s3)]);
assert.strictEqual(2, ds.writeValue(l4).height);
const l5 = new List([ds.writeValue(s1), s3]);
+10 -10
View File
@@ -1,7 +1,7 @@
// @flow
import Hash from './hash.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import Map from './map.js';
import Set from './set.js';
import type Value from './value.js';
@@ -56,7 +56,7 @@ export function getDatasTypes(): DatasTypes {
export default class Database {
_vs: ValueStore;
_rt: RootTracker;
_datasets: Promise<Map<string, RefValue<Commit>>>;
_datasets: Promise<Map<string, Ref<Commit>>>;
constructor(bs: BatchStore, cacheSize: number = 0) {
this._vs = new ValueStore(bs, cacheSize);
@@ -72,7 +72,7 @@ export default class Database {
return ds;
}
_datasetsFromRootRef(rootRef: Promise<Hash>): Promise<Map<string, RefValue<Commit>>> {
_datasetsFromRootRef(rootRef: Promise<Hash>): Promise<Map<string, Ref<Commit>>> {
return rootRef.then(rootRef => {
if (rootRef.isEmpty()) {
return Promise.resolve(new Map());
@@ -82,7 +82,7 @@ export default class Database {
});
}
headRef(datasetID: string): Promise<?RefValue<Commit>> {
headRef(datasetID: string): Promise<?Ref<Commit>> {
return this._datasets.then(datasets => datasets.get(datasetID));
}
@@ -90,7 +90,7 @@ export default class Database {
return this.headRef(datasetID).then(hr => hr ? this.readValue(hr.targetHash) : null);
}
datasets(): Promise<Map<string, RefValue<Commit>>> {
datasets(): Promise<Map<string, Ref<Commit>>> {
return this._datasets;
}
@@ -100,11 +100,11 @@ export default class Database {
}
writeValue<T: Value>(v: T): RefValue<T> {
writeValue<T: Value>(v: T): Ref<T> {
return this._vs.writeValue(v);
}
async _descendsFrom(commit: Commit, currentHeadRef: RefValue<Commit>): Promise<boolean> {
async _descendsFrom(commit: Commit, currentHeadRef: Ref<Commit>): Promise<boolean> {
let ancestors = commit.parents;
while (!(await ancestors.has(currentHeadRef))) {
if (ancestors.isEmpty()) {
@@ -148,12 +148,12 @@ export default class Database {
}
}
async function getAncestors(commits: Set<RefValue<Commit>>, store: Database):
Promise<Set<RefValue<Commit>>> {
async function getAncestors(commits: Set<Ref<Commit>>, store: Database):
Promise<Set<Ref<Commit>>> {
let ancestors = new Set();
await commits.map(async (commitRef) => {
const commit = await store.readValue(commitRef.targetHash);
await commit.parents.map(async (refValue) => ancestors = await ancestors.insert(refValue));
await commit.parents.map(async (ref) => ancestors = await ancestors.insert(ref));
});
return ancestors;
}
+3 -3
View File
@@ -3,7 +3,7 @@
import Commit from './commit.js';
import type Value from './value.js';
import type Database from './database.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import Set from './set.js';
export default class Dataset {
@@ -23,7 +23,7 @@ export default class Dataset {
return this._id;
}
headRef(): Promise<?RefValue<Commit>> {
headRef(): Promise<?Ref<Commit>> {
return this._store.headRef(this._id);
}
@@ -34,7 +34,7 @@ export default class Dataset {
// Commit updates the commit that a dataset points at. If parents is provided then an the promise
// is rejected if the commit does not descend from the parents.
async commit(v: Value,
parents: ?Array<RefValue<Commit>> = undefined): Promise<Dataset> {
parents: ?Array<Ref<Commit>> = undefined): Promise<Dataset> {
if (!parents) {
const headRef = await this.headRef();
parents = headRef ? [headRef] : [];
+2 -2
View File
@@ -3,7 +3,7 @@
import Chunk from './chunk.js';
import Database from './database.js';
import {makeTestingBatchStore} from './batch-store-adaptor.js';
import type RefValue from './ref-value.js';
import type Ref from './ref.js';
import Struct, {StructMirror} from './struct.js';
import type {TypeDesc} from './type.js';
import type Value from './value.js';
@@ -225,7 +225,7 @@ suite('Decode', () => {
],
];
const r = new JsonArrayReader(a, db);
const v: Map<RefValue<Value>, number> = r.readValue();
const v: Map<Ref<Value>, number> = r.readValue();
invariant(v instanceof Map);
const m = new Map([[rv1, 2], [rv2, 4]]);
+6 -6
View File
@@ -3,7 +3,7 @@
import {BlobLeafSequence, newBlobFromSequence} from './blob.js';
import Chunk from './chunk.js';
import Hash from './hash.js';
import RefValue, {constructRefValue} from './ref-value.js';
import Ref, {constructRef} from './ref.js';
import {newStructWithTypeNoValidation} from './struct.js';
import type Struct from './struct.js';
import type {NomsKind} from './noms-kind.js';
@@ -185,10 +185,10 @@ export class JsonArrayReader {
readMetaSequence(): Array<MetaTuple> {
const data: Array<MetaTuple> = [];
while (!this.atEnd()) {
const refValue = this.readValue();
const ref = this.readValue();
const v = this.readValue();
const numLeaves = this.readInt();
data.push(new MetaTuple(refValue, v, numLeaves));
data.push(new MetaTuple(ref, v, numLeaves));
}
return data;
@@ -202,10 +202,10 @@ export class JsonArrayReader {
return new OrderedMetaSequence(this._ds, t, this.readMetaSequence());
}
readRefValue(t: Type): RefValue {
readRef(t: Type): Ref {
const hash = this.readHash();
const height = this.readInt();
return constructRefValue(t, hash, height);
return constructRef(t, hash, height);
}
readValue(): any {
@@ -246,7 +246,7 @@ export class JsonArrayReader {
return newMapFromSequence(r2.readMapLeafSequence(t));
}
case Kind.Ref:
return this.readRefValue(t);
return this.readRef(t);
case Kind.Set: {
const isMeta = this.readBool();
const r2 = new JsonArrayReader(this.readArray(), this._ds);
+2 -2
View File
@@ -5,7 +5,7 @@ import {suite, setup, teardown, test} from 'mocha';
import {makeTestingBatchStore} from './batch-store-adaptor.js';
import Hash from './hash.js';
import {constructRefValue} from './ref-value.js';
import {constructRef} from './ref.js';
import {newStruct} from './struct.js';
import type {NomsKind} from './noms-kind.js';
import {encodeNomsValue, JsonArrayWriter} from './encode.js';
@@ -329,7 +329,7 @@ suite('Encode', () => {
const w = new JsonArrayWriter(db);
const hash = Hash.parse('sha1-0123456789abcdef0123456789abcdef01234567');
const t = makeRefType(blobType);
const v = constructRefValue(t, hash, 1);
const v = constructRef(t, hash, 1);
w.writeValue(v);
assert.deepEqual([Kind.Ref, Kind.Blob, hash.toString(), '1'], w.array);
+5 -5
View File
@@ -1,7 +1,7 @@
// @flow
import Chunk from './chunk.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import Struct, {StructMirror} from './struct.js';
import type {NomsKind} from './noms-kind.js';
import {encode as encodeBase64} from './base64.js';
@@ -65,7 +65,7 @@ export class JsonArrayWriter {
this.write(k);
}
writeRefValue(r: RefValue) {
writeRef(r: Ref) {
this.write(r.targetHash.toString());
this.writeInt(r.height);
}
@@ -109,7 +109,7 @@ export class JsonArrayWriter {
if (child && this._vw) {
this._vw.writeValue(child);
}
w2.writeValue(tuple.refValue);
w2.writeValue(tuple.ref);
w2.writeValue(tuple.value);
w2.writeInt(tuple.numLeaves);
}
@@ -180,9 +180,9 @@ export class JsonArrayWriter {
break;
}
case Kind.Ref: {
invariant(v instanceof RefValue,
invariant(v instanceof Ref,
() => `Failed to write Ref. Invalid type: ${describeTypeOfValue(v)}`);
this.writeRefValue(v);
this.writeRef(v);
break;
}
case Kind.Set: {
+1 -1
View File
@@ -47,7 +47,7 @@ export function diff(last: IndexedSequence, lastHeight: number, lastOffset: numb
invariant(lastHeight === currentHeight);
const splices = calcSplices(last.length, current.length, last.isMeta ?
(l, c) => equals(last.items[l].refValue, current.items[c].refValue) :
(l, c) => equals(last.items[l].ref, current.items[c].ref) :
(l, c) => equals(last.items[l], current.items[c]));
const splicesP = splices.map(splice => {
+5 -5
View File
@@ -5,7 +5,7 @@ import {suite, setup, teardown, test} from 'mocha';
import Database from './database.js';
import {makeTestingBatchStore} from './batch-store-adaptor.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import {newStruct} from './struct.js';
import {calcSplices} from './edit-distance.js';
import {
@@ -129,15 +129,15 @@ suite('List', () => {
test('LONG: list of ref, set of n numbers, length', async () => {
const nums = intSequence(testListSize);
const refValues = nums.map(n => new RefValue(newStruct('num', {n})));
const s = new List(refValues);
const refs = nums.map(n => new Ref(newStruct('num', {n})));
const s = new List(refs);
assert.strictEqual(s.hash.toString(), 'sha1-2e79d54322aa793d0e8d48380a28927a257a141a');
assert.strictEqual(testListSize, s.length);
const height = deriveCollectionHeight(s);
assert.isTrue(height > 0);
// height + 1 because the leaves are RefValue values (with height 1).
assert.strictEqual(height + 1, s.sequence.items[0].refValue.height);
// height + 1 because the leaves are Ref values (with height 1).
assert.strictEqual(height + 1, s.sequence.items[0].ref.height);
});
test('LONG: insert', async () => {
+3 -3
View File
@@ -15,7 +15,7 @@ import {invariant} from './assert.js';
import {MetaTuple, newIndexedMetaSequenceBoundaryChecker,
newIndexedMetaSequenceChunkFn} from './meta-sequence.js';
import {sha1Size} from './hash.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import {getValueChunks} from './sequence.js';
import {makeListType, makeUnionType, getTypeOfValue} from './type.js';
import {equals} from './compare.js';
@@ -27,7 +27,7 @@ const listPattern = ((1 << 6) | 0) - 1;
function newListLeafChunkFn<T: Value>(vr: ?ValueReader): makeChunkFn {
return (items: Array<T>) => {
const list = newListFromSequence(newListLeafSequence(vr, items));
const mt = new MetaTuple(new RefValue(list), items.length, items.length, list);
const mt = new MetaTuple(new Ref(list), items.length, items.length, list);
return [mt, list];
};
}
@@ -133,7 +133,7 @@ export function newListFromSequence<T: Value>(sequence: IndexedSequence): List<T
}
export class ListLeafSequence<T: Value> extends IndexedSequence<T> {
get chunks(): Array<RefValue> {
get chunks(): Array<Ref> {
return getValueChunks(this.items);
}
+8 -8
View File
@@ -5,7 +5,7 @@ import {suite, setup, teardown, test} from 'mocha';
import Database from './database.js';
import MemoryStore from './memory-store.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import BatchStore from './batch-store.js';
import {BatchStoreAdaptorDelegate, makeTestingBatchStore} from './batch-store-adaptor.js';
import Struct, {newStruct} from './struct.js';
@@ -87,7 +87,7 @@ suite('BuildMap', () => {
const height = deriveCollectionHeight(m);
assert.isTrue(height > 0);
assert.strictEqual(height, deriveCollectionHeight(m2));
assert.strictEqual(height, m.sequence.items[0].refValue.height);
assert.strictEqual(height, m.sequence.items[0].ref.height);
});
test('LONG: map of ref to ref, set of n numbers', () => {
@@ -96,13 +96,13 @@ suite('BuildMap', () => {
kvs.push([i, i + 1]);
}
const kvRefs = kvs.map(entry => entry.map(n => new RefValue(newStruct('num', {n}))));
const kvRefs = kvs.map(entry => entry.map(n => new Ref(newStruct('num', {n}))));
const m = new Map(kvRefs);
assert.strictEqual(m.hash.toString(), 'sha1-5c9a17f6da0ebfebc1f82f498ac46992fad85250');
const height = deriveCollectionHeight(m);
assert.isTrue(height > 0);
// height + 1 because the leaves are RefValue values (with height 1).
assert.strictEqual(height + 1, m.sequence.items[0].refValue.height);
// height + 1 because the leaves are Ref values (with height 1).
assert.strictEqual(height + 1, m.sequence.items[0].ref.height);
});
test('LONG: set', async () => {
@@ -208,7 +208,7 @@ suite('BuildMap', () => {
assert.strictEqual(m.hash.toString(), 'sha1-3840c9c93d79663e77a60f13f2877a8f5843da38');
const height = deriveCollectionHeight(m);
assert.isTrue(height > 0);
assert.strictEqual(height, m.sequence.items[0].refValue.height);
assert.strictEqual(height, m.sequence.items[0].ref.height);
// has
for (let i = 0; i < keys.length; i += 5) {
@@ -596,7 +596,7 @@ suite('CompoundMap', () => {
const chunks = m.chunks;
const sequence = m.sequence;
assert.equal(2, chunks.length);
assert.deepEqual(sequence.items[0].refValue, chunks[0]);
assert.deepEqual(sequence.items[1].refValue, chunks[1]);
assert.deepEqual(sequence.items[0].ref, chunks[0]);
assert.deepEqual(sequence.items[1].ref, chunks[1]);
});
});
+4 -4
View File
@@ -1,7 +1,7 @@
// @flow
import BuzHashBoundaryChecker from './buzhash-boundary-checker.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import type {ValueReader} from './value-store.js';
import type {BoundaryChecker, makeChunkFn} from './sequence-chunker.js';
import type Value from './value.js'; // eslint-disable-line no-unused-vars
@@ -35,12 +35,12 @@ function newMapLeafChunkFn<K: Value, V: Value>(vr: ?ValueReader):
if (items.length > 0) {
indexValue = items[items.length - 1][KEY];
if (indexValue instanceof ValueBase) {
indexValue = new RefValue(indexValue);
indexValue = new Ref(indexValue);
}
}
const nm = newMapFromSequence(newMapLeafSequence(vr, items));
const mt = new MetaTuple(new RefValue(nm), indexValue, items.length, nm);
const mt = new MetaTuple(new Ref(nm), indexValue, items.length, nm);
return [mt, nm];
};
}
@@ -204,7 +204,7 @@ export class MapLeafSequence<K: Value, V: Value> extends
return equals(entry[KEY], other[KEY]) && equals(entry[VALUE], other[VALUE]);
}
get chunks(): Array<RefValue> {
get chunks(): Array<Ref> {
const chunks = [];
for (const entry of this.items) {
if (entry[KEY] instanceof ValueBase) {
+13 -13
View File
@@ -6,7 +6,7 @@ import {suite, test} from 'mocha';
import List from './list.js';
import {MetaTuple, newOrderedMetaSequenceChunkFn, newIndexedMetaSequenceChunkFn,} from
'./meta-sequence.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import Set from './set.js';
import {Kind} from './noms-kind.js';
@@ -14,33 +14,33 @@ suite('MetaSequence', () => {
test('calculate ordered sequence MetaTuple height', async () => {
const set1 = new Set(['bar', 'baz']);
const set2 = new Set(['foo', 'qux', 'zoo']);
const mt1 = new MetaTuple(new RefValue(set1), 'baz', 2, set1);
const mt2 = new MetaTuple(new RefValue(set2), 'zoo', 3, set2);
const mt1 = new MetaTuple(new Ref(set1), 'baz', 2, set1);
const mt2 = new MetaTuple(new Ref(set2), 'zoo', 3, set2);
assert.strictEqual(1, mt1.refValue.height);
assert.strictEqual(1, mt2.refValue.height);
assert.strictEqual(1, mt1.ref.height);
assert.strictEqual(1, mt2.ref.height);
const oseq1 = newOrderedMetaSequenceChunkFn(Kind.Set, null)([mt1, mt2])[0];
assert.strictEqual(2, oseq1.refValue.height);
assert.strictEqual(2, oseq1.ref.height);
// At this point the sequence isn't really valid because I'm reusing a MetaNode, which isn't
// allowed (the values are now out of order). For the purpose of testing height, it's fine.
const oseq2 = newOrderedMetaSequenceChunkFn(Kind.Set, null)([oseq1, oseq1])[0];
assert.strictEqual(3, oseq2.refValue.height);
assert.strictEqual(3, oseq2.ref.height);
});
test('calculate indexed sequence MetaTuple height', async () => {
const list1 = new List(['bar', 'baz']);
const list2 = new List(['foo', 'qux', 'zoo']);
const mt1 = new MetaTuple(new RefValue(list1), 2, 2, list1);
const mt2 = new MetaTuple(new RefValue(list2), 3, 3, list2);
const mt1 = new MetaTuple(new Ref(list1), 2, 2, list1);
const mt2 = new MetaTuple(new Ref(list2), 3, 3, list2);
assert.strictEqual(1, mt1.refValue.height);
assert.strictEqual(1, mt2.refValue.height);
assert.strictEqual(1, mt1.ref.height);
assert.strictEqual(1, mt2.ref.height);
const iseq1 = newIndexedMetaSequenceChunkFn(Kind.List, null)([mt1, mt2])[0];
assert.strictEqual(2, iseq1.refValue.height);
assert.strictEqual(2, iseq1.ref.height);
const iseq2 = newIndexedMetaSequenceChunkFn(Kind.List, null)([iseq1, iseq1])[0];
assert.strictEqual(3, iseq2.refValue.height);
assert.strictEqual(3, iseq2.ref.height);
});
});
+16 -16
View File
@@ -11,7 +11,7 @@ import {makeListType, makeUnionType, blobType, makeSetType, makeMapType} from '.
import {IndexedSequence} from './indexed-sequence.js';
import {invariant, notNull} from './assert.js';
import {OrderedSequence} from './ordered-sequence.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import Sequence from './sequence.js';
import {Kind} from './noms-kind.js';
import type {NomsKind} from './noms-kind.js';
@@ -24,13 +24,13 @@ import {equals} from './compare.js';
export type MetaSequence = Sequence<MetaTuple>;
export class MetaTuple<K> {
refValue: RefValue;
ref: Ref;
value: K;
numLeaves: number;
child: ?Collection;
constructor(refValue: RefValue, value: K, numLeaves: number, child: ?Collection = null) {
this.refValue = refValue;
constructor(ref: Ref, value: K, numLeaves: number, child: ?Collection = null) {
this.ref = ref;
this.child = child;
this.value = value;
this.numLeaves = numLeaves;
@@ -39,8 +39,8 @@ export class MetaTuple<K> {
getSequence(vr: ?ValueReader): Promise<Sequence> {
return this.child ?
Promise.resolve(this.child.sequence) :
notNull(vr).readValue(this.refValue.targetHash).then((c: Collection) => {
invariant(c, () => `Could not read sequence ${this.refValue.targetHash}`);
notNull(vr).readValue(this.ref.targetHash).then((c: Collection) => {
invariant(c, () => `Could not read sequence ${this.ref.targetHash}`);
return c.sequence;
});
}
@@ -48,7 +48,7 @@ export class MetaTuple<K> {
// The elemTypes of the collection inside the Ref<Collection<?, ?>>
function getCollectionTypes<K>(tuple: MetaTuple<K>): Type[] {
return tuple.refValue.type.desc.elemTypes[0].desc.elemTypes;
return tuple.ref.type.desc.elemTypes[0].desc.elemTypes;
}
export function newListMetaSequence(vr: ?ValueReader, items: Array<MetaTuple<number>>):
@@ -82,7 +82,7 @@ export class IndexedMetaSequence extends IndexedSequence<MetaTuple<number>> {
return this._offsets[this._offsets.length - 1];
}
get chunks(): Array<RefValue> {
get chunks(): Array<Ref> {
return getMetaSequenceChunks(this);
}
@@ -173,7 +173,7 @@ export class OrderedMetaSequence<K: Value> extends OrderedSequence<K, MetaTuple<
return this._numLeaves;
}
get chunks(): Array<RefValue> {
get chunks(): Array<Ref> {
return getMetaSequenceChunks(this);
}
@@ -191,7 +191,7 @@ export class OrderedMetaSequence<K: Value> extends OrderedSequence<K, MetaTuple<
}
equalsAt(idx: number, other: MetaTuple): boolean {
return equals(this.items[idx].refValue, other.refValue);
return equals(this.items[idx].ref, other.ref);
}
}
@@ -206,7 +206,7 @@ export function newOrderedMetaSequenceChunkFn(kind: NomsKind, vr: ?ValueReader):
invariant(kind === Kind.Set);
col = newSetFromSequence(newSetMetaSequence(vr, tuples));
}
return [new MetaTuple(new RefValue(col), last.value, numLeaves, col), col];
return [new MetaTuple(new Ref(col), last.value, numLeaves, col), col];
};
}
@@ -216,7 +216,7 @@ const objectPattern = ((1 << 6) | 0) - 1;
export function newOrderedMetaSequenceBoundaryChecker(): BoundaryChecker<MetaTuple> {
return new BuzHashBoundaryChecker(orderedSequenceWindowSize, sha1Size, objectPattern,
(mt: MetaTuple) => mt.refValue.targetHash.digest
(mt: MetaTuple) => mt.ref.targetHash.digest
);
}
@@ -233,16 +233,16 @@ export function newIndexedMetaSequenceChunkFn(kind: NomsKind, vr: ?ValueReader):
invariant(kind === Kind.Blob);
col = newBlobFromSequence(newBlobMetaSequence(vr, tuples));
}
return [new MetaTuple(new RefValue(col), sum, sum, col), col];
return [new MetaTuple(new Ref(col), sum, sum, col), col];
};
}
export function newIndexedMetaSequenceBoundaryChecker(): BoundaryChecker<MetaTuple> {
return new BuzHashBoundaryChecker(objectWindowSize, sha1Size, objectPattern,
(mt: MetaTuple) => mt.refValue.targetHash.digest
(mt: MetaTuple) => mt.ref.targetHash.digest
);
}
function getMetaSequenceChunks(ms: MetaSequence): Array<RefValue> {
return ms.items.map(mt => mt.refValue);
function getMetaSequenceChunks(ms: MetaSequence): Array<Ref> {
return ms.items.map(mt => mt.ref);
}
+1 -1
View File
@@ -11,7 +11,7 @@ export {default as Chunk} from './chunk.js';
export {default as HttpBatchStore} from './http-batch-store.js';
export {default as MemoryStore} from './memory-store.js';
export {default as Hash, emptyHash} from './hash.js';
export {default as RefValue} from './ref-value.js';
export {default as Ref} from './ref.js';
export {
default as Struct,
StructMirror,
+3 -3
View File
@@ -12,10 +12,10 @@ import {newStruct} from './struct.js';
suite('Path', () => {
async function assertPathEqual(expect: any, refValue: Value, path: Path):
async function assertPathEqual(expect: any, ref: Value, path: Path):
Promise<void> {
// $FlowIssue: need to be able to pass in null for refValue
const actual = await path.resolve(refValue);
// $FlowIssue: need to be able to pass in null for ref
const actual = await path.resolve(ref);
if (actual === undefined || expect === undefined) {
assert.strictEqual(expect, actual);
return;
+5 -5
View File
@@ -11,22 +11,22 @@ import {invariant} from './assert.js';
import {getTypeOfValue, makeRefType} from './type.js';
import {ValueBase, getChunksOfValue} from './value.js';
export function constructRefValue(t: Type, targetHash: Hash, height: number): RefValue {
export function constructRef(t: Type, targetHash: Hash, height: number): Ref {
invariant(t.kind === Kind.Ref, () => `Not a Ref type: ${describeType(t)}`);
invariant(!targetHash.isEmpty());
invariant(height > 0);
const rv = Object.create(RefValue.prototype);
const rv = Object.create(Ref.prototype);
rv._type = t;
rv.targetHash = targetHash;
rv.height = height;
return rv;
}
export default class RefValue<T: Value> extends ValueBase {
export default class Ref<T: Value> extends ValueBase {
_type: Type;
// Hash of the value this points to.
targetHash: Hash;
// The length of the longest path of RefValues to find any leaf in the graph.
// The length of the longest path of Refs to find any leaf in the graph.
// By definition this must be > 0.
height: number;
@@ -45,7 +45,7 @@ export default class RefValue<T: Value> extends ValueBase {
return vr.readValue(this.targetHash);
}
get chunks(): Array<RefValue> {
get chunks(): Array<Ref> {
return [this];
}
}
+3 -3
View File
@@ -4,7 +4,7 @@ import type {ValueReader} from './value-store.js';
import {invariant, notNull} from './assert.js';
import {AsyncIterator} from './async-iterator.js';
import type {AsyncIteratorResult} from './async-iterator.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import type {Type} from './type.js';
import {ValueBase} from './value.js';
@@ -39,7 +39,7 @@ export default class Sequence<T> {
return Promise.resolve(null);
}
get chunks(): Array<RefValue> {
get chunks(): Array<Ref> {
return [];
}
@@ -293,7 +293,7 @@ export function search(length: number, compare: (i: number) => number): number {
return lo;
}
export function getValueChunks<T>(items: Array<T>): Array<RefValue> {
export function getValueChunks<T>(items: Array<T>): Array<Ref> {
const chunks = [];
for (const item of items) {
if (item instanceof ValueBase) {
+13 -13
View File
@@ -6,7 +6,7 @@ import {suite, setup, teardown, test} from 'mocha';
import Chunk from './chunk.js';
import Database from './database.js';
import MemoryStore from './memory-store.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import BatchStore from './batch-store.js';
import {BatchStoreAdaptorDelegate, makeTestingBatchStore} from './batch-store-adaptor.js';
import {newStruct} from './struct.js';
@@ -85,7 +85,7 @@ suite('BuildSet', () => {
assert.strictEqual(s.hash.toString(), 'sha1-f10d8ccbc2270bb52bb988a0cadff912e2723eed');
const height = deriveCollectionHeight(s);
assert.isTrue(height > 0);
assert.strictEqual(height, s.sequence.items[0].refValue.height);
assert.strictEqual(height, s.sequence.items[0].ref.height);
// has
for (let i = 0; i < structs.length; i++) {
@@ -95,13 +95,13 @@ suite('BuildSet', () => {
test('LONG: set of ref, set of n numbers', async () => {
const nums = firstNNumbers(testSetSize);
const refValues = nums.map(n => new RefValue(newStruct('num', {n})));
const s = new Set(refValues);
const refs = nums.map(n => new Ref(newStruct('num', {n})));
const s = new Set(refs);
assert.strictEqual(s.hash.toString(), 'sha1-14eeb2d1835011bf3e018121ba3274bc08e634e5');
const height = deriveCollectionHeight(s);
assert.isTrue(height > 0);
// height + 1 because the leaves are RefValue values (with height 1).
assert.strictEqual(height + 1, s.sequence.items[0].refValue.height);
// height + 1 because the leaves are Ref values (with height 1).
assert.strictEqual(height + 1, s.sequence.items[0].ref.height);
});
test('LONG: insert', async () => {
@@ -179,7 +179,7 @@ suite('BuildSet', () => {
assert.strictEqual(s.hash.toString(), 'sha1-84ce63b4fb804fe9668133bf5d3136cfffcdc788');
const height = deriveCollectionHeight(s);
assert.isTrue(height > 0);
assert.strictEqual(height, s.sequence.items[0].refValue.height);
assert.strictEqual(height, s.sequence.items[0].ref.height);
// has
for (let i = 0; i < vals.length; i += 5) {
@@ -275,10 +275,10 @@ suite('SetLeaf', () => {
});
test('chunks', () => {
const refValues = ['x', 'a', 'b'].map(c => db.writeValue(c));
refValues.sort(compare);
const l = new Set(['z', ...refValues]);
assert.deepEqual(refValues, l.chunks);
const refs = ['x', 'a', 'b'].map(c => db.writeValue(c));
refs.sort(compare);
const l = new Set(['z', ...refs]);
assert.deepEqual(refs, l.chunks);
});
});
@@ -611,7 +611,7 @@ suite('CompoundSet', () => {
const chunks = s.chunks;
const sequence = s.sequence;
assert.equal(2, chunks.length);
assert.deepEqual(sequence.items[0].refValue, chunks[0]);
assert.deepEqual(sequence.items[1].refValue, chunks[1]);
assert.deepEqual(sequence.items[0].ref, chunks[0]);
assert.deepEqual(sequence.items[1].ref, chunks[1]);
});
});
+5 -5
View File
@@ -1,7 +1,7 @@
// @flow
import BuzHashBoundaryChecker from './buzhash-boundary-checker.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import type {ValueReader} from './value-store.js';
import type {BoundaryChecker, makeChunkFn} from './sequence-chunker.js';
import type Value from './value.js'; // eslint-disable-line no-unused-vars
@@ -28,16 +28,16 @@ const setPattern = ((1 << 6) | 0) - 1;
function newSetLeafChunkFn<T:Value>(vr: ?ValueReader): makeChunkFn {
return (items: Array<T>) => {
let indexValue: ?(T | RefValue) = null;
let indexValue: ?(T | Ref) = null;
if (items.length > 0) {
indexValue = items[items.length - 1];
if (indexValue instanceof ValueBase) {
indexValue = new RefValue(indexValue);
indexValue = new Ref(indexValue);
}
}
const ns = newSetFromSequence(newSetLeafSequence(vr, items));
const mt = new MetaTuple(new RefValue(ns), indexValue, items.length, ns);
const mt = new MetaTuple(new Ref(ns), indexValue, items.length, ns);
return [mt, ns];
};
}
@@ -212,7 +212,7 @@ export class SetLeafSequence<K: Value> extends OrderedSequence<K, K> {
return equals(this.items[idx], other);
}
get chunks(): Array<RefValue> {
get chunks(): Array<Ref> {
return getValueChunks(this.items);
}
}
+2 -2
View File
@@ -1,7 +1,7 @@
// @flow
import assertSubtype from './assert-type.js';
import type RefValue from './ref-value.js';
import type Ref from './ref.js';
import type {Type, StructDesc} from './type.js';
import type Value from './value.js';
import {Kind} from './noms-kind.js';
@@ -51,7 +51,7 @@ export default class Struct extends ValueBase {
return this._type;
}
get chunks(): Array<RefValue> {
get chunks(): Array<Ref> {
const mirror = new StructMirror(this);
const chunks = [];
+1 -1
View File
@@ -103,7 +103,7 @@ export function intSequence(count: number, start: number = 0): Array<number> {
}
export function deriveCollectionHeight(col: Collection): number {
// Note: not using seq.items[0].refValue.height because the purpose of this method is to
// Note: not using seq.items[0].ref.height because the purpose of this method is to
// be redundant.
return col.sequence.isMeta ? 1 + deriveCollectionHeight(notNull(col.sequence.items[0].child)) : 0;
}
+2 -2
View File
@@ -1,7 +1,7 @@
// @flow
import type Hash from './hash.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import type {NomsKind} from './noms-kind.js';
import {invariant} from './assert.js';
import {isPrimitiveKind, Kind} from './noms-kind.js';
@@ -121,7 +121,7 @@ export class Type<T: TypeDesc> extends ValueBase {
return typeType;
}
get chunks(): Array<RefValue> {
get chunks(): Array<Ref> {
return [];
}
+8 -8
View File
@@ -2,7 +2,7 @@
import Chunk from './chunk.js';
import Hash, {emptyHash} from './hash.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import type BatchStore from './batch-store.js';
import type Value from './value.js';
import {
@@ -19,7 +19,7 @@ import {describeType, describeTypeOfValue} from './encode-human-readable.js';
import {equals} from './compare.js';
export interface ValueWriter {
writeValue<T: Value>(v: T, t: ?Type): RefValue<T>
writeValue<T: Value>(v: T, t: ?Type): Ref<T>
}
export interface ValueReader {
@@ -30,7 +30,7 @@ export interface ValueReader {
export interface ValueReadWriter {
// TODO: This should return Promise<?Value>
readValue(hash: Hash): Promise<any>;
writeValue<T: Value>(v: T): RefValue<T>;
writeValue<T: Value>(v: T): Ref<T>;
}
export default class ValueStore {
@@ -70,20 +70,20 @@ export default class ValueStore {
return v;
}
writeValue<T: Value>(v: T): RefValue<T> {
writeValue<T: Value>(v: T): Ref<T> {
const t = getTypeOfValue(v);
const chunk = encodeNomsValue(v, this);
invariant(!chunk.isEmpty());
const {hash} = chunk;
const refValue = new RefValue(v);
const ref = new Ref(v);
const entry = this._knownHashes.get(hash);
if (entry && entry.present) {
return refValue;
return ref;
}
const hints = this._knownHashes.checkChunksInCache(v);
this._bs.schedulePut(chunk, hints);
this._knownHashes.add(hash, new HashCacheEntry(true, t));
return refValue;
return ref;
}
async flush(): Promise<void> {
@@ -258,7 +258,7 @@ class HashCache {
}
}
function getTargetType(refVal: RefValue): Type {
function getTargetType(refVal: Ref): Type {
invariant(refVal.type.kind === Kind.Ref, refVal.type.kind);
return refVal.type.elemTypes[0];
}
+3 -3
View File
@@ -4,7 +4,7 @@ import type Hash from './hash.js';
import type {primitive} from './primitives.js';
import {ensureHash} from './get-hash.js';
import type {Type} from './type.js';
import type RefValue from './ref-value.js';
import type Ref from './ref.js';
export class ValueBase {
_hash: ?Hash;
@@ -21,7 +21,7 @@ export class ValueBase {
return this._hash = ensureHash(this._hash, this);
}
get chunks(): Array<RefValue> {
get chunks(): Array<Ref> {
return [];
}
}
@@ -29,7 +29,7 @@ export class ValueBase {
type Value = primitive | ValueBase;
export type {Value as default};
export function getChunksOfValue(v: Value): Array<RefValue> {
export function getChunksOfValue(v: Value): Array<Ref> {
if (v instanceof ValueBase) {
return v.chunks;
}
+2 -2
View File
@@ -4,7 +4,7 @@ import Blob from './blob.js';
import List from './list.js';
import Set from './set.js';
import Map from './map.js';
import RefValue from './ref-value.js';
import Ref from './ref.js';
import Struct, {StructMirror} from './struct.js';
import type Database from './database.js';
@@ -42,7 +42,7 @@ export default async function walk(v: Value, ds: Database, cb: walkCb): Promise<
return;
}
if (v instanceof RefValue) {
if (v instanceof Ref) {
return walk(await v.targetValue(ds), ds, cb);
}