mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-29 03:06:35 -05:00
Noms data structure names (#1525)
* Change to default exports * Rename NomsX to X in (Blob, List, Map, Set) * Increment version
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@attic/noms",
|
||||
"version": "30.0.0",
|
||||
"version": "31.0.0",
|
||||
"description": "Noms JS SDK",
|
||||
"repository": "https://github.com/attic-labs/noms",
|
||||
"main": "dist/commonjs/noms.js",
|
||||
|
||||
+4
-4
@@ -2,7 +2,7 @@
|
||||
|
||||
import {blobType, refOfBlobType} from './type.js';
|
||||
import {assert} from 'chai';
|
||||
import {newBlob, BlobWriter, NomsBlob} from './blob.js';
|
||||
import Blob, {newBlob, BlobWriter} from './blob.js';
|
||||
import {suite, test} from 'mocha';
|
||||
import {
|
||||
assertChunkCountAndType,
|
||||
@@ -19,7 +19,7 @@ import {equals} from './compare.js';
|
||||
|
||||
suite('Blob', () => {
|
||||
|
||||
async function assertReadFull(expect: Uint8Array, blob: NomsBlob): Promise<void> {
|
||||
async function assertReadFull(expect: Uint8Array, blob: Blob): Promise<void> {
|
||||
const length = expect.length;
|
||||
const reader = blob.getReader();
|
||||
let i = 0;
|
||||
@@ -36,7 +36,7 @@ suite('Blob', () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function testPrependChunkDiff(buff: Uint8Array, blob: NomsBlob, expectCount: number):
|
||||
async function testPrependChunkDiff(buff: Uint8Array, blob: Blob, expectCount: number):
|
||||
Promise<void> {
|
||||
const nb = new Uint8Array(buff.length + 1);
|
||||
for (let i = 0; i < buff.length; i++) {
|
||||
@@ -47,7 +47,7 @@ suite('Blob', () => {
|
||||
assert.strictEqual(expectCount, chunkDiffCount(blob, v2));
|
||||
}
|
||||
|
||||
async function testAppendChunkDiff(buff: Uint8Array, blob: NomsBlob, expectCount: number):
|
||||
async function testAppendChunkDiff(buff: Uint8Array, blob: Blob, expectCount: number):
|
||||
Promise<void> {
|
||||
const nb = new Uint8Array(buff.length + 1);
|
||||
for (let i = 0; i < buff.length; i++) {
|
||||
|
||||
+5
-5
@@ -14,7 +14,7 @@ import {SequenceChunker} from './sequence-chunker.js';
|
||||
import type {BoundaryChecker, makeChunkFn} from './sequence-chunker.js';
|
||||
import {Kind} from './noms-kind.js';
|
||||
|
||||
export class NomsBlob extends Collection<IndexedSequence> {
|
||||
export default class Blob extends Collection<IndexedSequence> {
|
||||
getReader(): BlobReader {
|
||||
return new BlobReader(this.sequence.newCursorAt(0));
|
||||
}
|
||||
@@ -70,7 +70,7 @@ const blobPattern = ((1 << 11) | 0) - 1; // Avg Chunk Size: 2k
|
||||
function newBlobLeafChunkFn(vr: ?ValueReader = null): makeChunkFn {
|
||||
return (items: Array<number>) => {
|
||||
const blobLeaf = new BlobLeafSequence(vr, new Uint8Array(items));
|
||||
const blob = new NomsBlob(blobLeaf);
|
||||
const blob = new Blob(blobLeaf);
|
||||
const mt = new MetaTuple(new RefValue(blob), items.length, items.length, blob);
|
||||
return [mt, blob];
|
||||
};
|
||||
@@ -80,7 +80,7 @@ function newBlobLeafBoundaryChecker(): BoundaryChecker<number> {
|
||||
return new BuzHashBoundaryChecker(blobWindowSize, 1, blobPattern, (v: number) => v);
|
||||
}
|
||||
|
||||
export function newBlob(bytes: Uint8Array): Promise<NomsBlob> {
|
||||
export function newBlob(bytes: Uint8Array): Promise<Blob> {
|
||||
const w = new BlobWriter();
|
||||
w.write(bytes);
|
||||
return w.close().then(() => w.blob);
|
||||
@@ -90,7 +90,7 @@ type BlobWriterState = 'writable' | 'closing' | 'closed';
|
||||
|
||||
export class BlobWriter {
|
||||
_state: BlobWriterState;
|
||||
_blob: ?NomsBlob;
|
||||
_blob: ?Blob;
|
||||
_chunker: SequenceChunker;
|
||||
|
||||
constructor() {
|
||||
@@ -114,7 +114,7 @@ export class BlobWriter {
|
||||
this._state = 'closed';
|
||||
}
|
||||
|
||||
get blob(): NomsBlob {
|
||||
get blob(): Blob {
|
||||
assert(this._state === 'closed');
|
||||
invariant(this._blob);
|
||||
return this._blob;
|
||||
|
||||
+3
-3
@@ -3,11 +3,11 @@
|
||||
import type Struct from './struct.js';
|
||||
import type {valueOrPrimitive} from './value.js';
|
||||
import type RefValue from './ref-value.js';
|
||||
import type {NomsSet} from './set.js';
|
||||
import type Set from './set.js';
|
||||
|
||||
export interface Commit extends Struct {
|
||||
value: valueOrPrimitive; // readonly
|
||||
setValue(value: valueOrPrimitive): Commit;
|
||||
parents: NomsSet<RefValue<Commit>>; // readonly
|
||||
setParents(value: NomsSet<RefValue<Commit>>): Commit;
|
||||
parents: Set<RefValue<Commit>>; // readonly
|
||||
setParents(value: Set<RefValue<Commit>>): Commit;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import {suite, test} from 'mocha';
|
||||
import {makeTestingBatchStore} from './batch-store-adaptor.js';
|
||||
import {emptyRef} from './ref.js';
|
||||
import {assert} from 'chai';
|
||||
import {default as Database, newCommit} from './database.js';
|
||||
import Database, {newCommit} from './database.js';
|
||||
import {invariant, notNull} from './assert.js';
|
||||
import {newList} from './list.js';
|
||||
import {newMap} from './map.js';
|
||||
|
||||
+11
-11
@@ -1,10 +1,10 @@
|
||||
// @flow
|
||||
|
||||
import Ref from './ref.js';
|
||||
import {default as RefValue} from './ref-value.js';
|
||||
import RefValue from './ref-value.js';
|
||||
import {newStructWithType} from './struct.js';
|
||||
import type {NomsMap} from './map.js';
|
||||
import type {NomsSet} from './set.js';
|
||||
import type Map from './map.js';
|
||||
import type Set from './set.js';
|
||||
import type {valueOrPrimitive} from './value.js';
|
||||
import type {RootTracker} from './chunk-store.js';
|
||||
import ValueStore from './value-store.js';
|
||||
@@ -30,8 +30,8 @@ type DatasTypes = {
|
||||
commitMapType: Type,
|
||||
};
|
||||
|
||||
let emptyCommitMap: Promise<NomsMap<string, RefValue<Commit>>>;
|
||||
function getEmptyCommitMap(): Promise<NomsMap<string, RefValue<Commit>>> {
|
||||
let emptyCommitMap: Promise<Map<string, RefValue<Commit>>>;
|
||||
function getEmptyCommitMap(): Promise<Map<string, RefValue<Commit>>> {
|
||||
if (!emptyCommitMap) {
|
||||
emptyCommitMap = newMap([]);
|
||||
}
|
||||
@@ -67,7 +67,7 @@ export function getDatasTypes(): DatasTypes {
|
||||
export default class Database {
|
||||
_vs: ValueStore;
|
||||
_rt: RootTracker;
|
||||
_datasets: Promise<NomsMap<string, RefValue<Commit>>>;
|
||||
_datasets: Promise<Map<string, RefValue<Commit>>>;
|
||||
|
||||
constructor(bs: BatchStore, cacheSize: number = 0) {
|
||||
this._vs = new ValueStore(bs, cacheSize);
|
||||
@@ -83,7 +83,7 @@ export default class Database {
|
||||
return ds;
|
||||
}
|
||||
|
||||
_datasetsFromRootRef(rootRef: Promise<Ref>): Promise<NomsMap<string, RefValue<Commit>>> {
|
||||
_datasetsFromRootRef(rootRef: Promise<Ref>): Promise<Map<string, RefValue<Commit>>> {
|
||||
return rootRef.then(rootRef => {
|
||||
if (rootRef.isEmpty()) {
|
||||
return getEmptyCommitMap();
|
||||
@@ -101,7 +101,7 @@ export default class Database {
|
||||
return this.headRef(datasetID).then(hr => hr ? this.readValue(hr.targetRef) : null);
|
||||
}
|
||||
|
||||
datasets(): Promise<NomsMap<string, RefValue<Commit>>> {
|
||||
datasets(): Promise<Map<string, RefValue<Commit>>> {
|
||||
return this._datasets;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ export default class Database {
|
||||
async commit(datasetId: string, commit: Commit): Promise<Database> {
|
||||
const currentRootRefP = this._rt.getRoot();
|
||||
const datasetsP = this._datasetsFromRootRef(currentRootRefP);
|
||||
let currentDatasets = await (datasetsP:Promise<NomsMap>);
|
||||
let currentDatasets = await (datasetsP:Promise<Map>);
|
||||
const currentRootRef = await currentRootRefP;
|
||||
const commitRef = this.writeValue(commit);
|
||||
|
||||
@@ -159,8 +159,8 @@ export default class Database {
|
||||
}
|
||||
}
|
||||
|
||||
async function getAncestors(commits: NomsSet<RefValue<Commit>>, store: Database):
|
||||
Promise<NomsSet<RefValue<Commit>>> {
|
||||
async function getAncestors(commits: Set<RefValue<Commit>>, store: Database):
|
||||
Promise<Set<RefValue<Commit>>> {
|
||||
let ancestors = await newSet([]);
|
||||
await commits.map(async (commitRef) => {
|
||||
const commit = await store.readValue(commitRef.targetRef);
|
||||
|
||||
+40
-39
@@ -4,7 +4,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 {default as Struct, StructMirror} from './struct.js';
|
||||
import Struct, {StructMirror} from './struct.js';
|
||||
import type {TypeDesc} from './type.js';
|
||||
import type {Value} from './value.js';
|
||||
import {assert} from 'chai';
|
||||
@@ -26,10 +26,11 @@ import {encode as encodeBase64} from './base64.js';
|
||||
import {newListMetaSequence, MetaTuple, newSetMetaSequence} from './meta-sequence.js';
|
||||
import {invariant, notNull} from './assert.js';
|
||||
import {Kind} from './noms-kind.js';
|
||||
import {newListLeafSequence, NomsList} from './list.js';
|
||||
import {newMapLeafSequence, NomsMap} from './map.js';
|
||||
import {NomsBlob, newBlob} from './blob.js';
|
||||
import {NomsSet, newSetLeafSequence} from './set.js';
|
||||
import List, {newListLeafSequence} from './list.js';
|
||||
import Map, {newMapLeafSequence} from './map.js';
|
||||
import Blob, {newBlob} from './blob.js';
|
||||
// Set is already in use in this file.
|
||||
import NomsSet, {newSetLeafSequence} from './set.js';
|
||||
import {suite, test} from 'mocha';
|
||||
import {equals} from './compare.js';
|
||||
|
||||
@@ -109,10 +110,10 @@ suite('Decode', () => {
|
||||
const a = [Kind.List, Kind.Number, false,
|
||||
[Kind.Number, '0', Kind.Number, '1', Kind.Number, '2', Kind.Number, '3']];
|
||||
const r = new JsonArrayReader(a, ds);
|
||||
const v: NomsList<number> = r.readValue();
|
||||
invariant(v instanceof NomsList);
|
||||
const v: List<number> = r.readValue();
|
||||
invariant(v instanceof List);
|
||||
|
||||
const l = new NomsList(newListLeafSequence(ds, [0, 1, 2, 3]));
|
||||
const l = new List(newListLeafSequence(ds, [0, 1, 2, 3]));
|
||||
assert.isTrue(equals(l, v));
|
||||
});
|
||||
|
||||
@@ -121,8 +122,8 @@ suite('Decode', () => {
|
||||
const a = [Kind.List, Kind.Union, 3, Kind.Bool, Kind.Number, Kind.String, false,
|
||||
[Kind.Number, '1', Kind.String, 'hi', Kind.Bool, true]];
|
||||
const r = new JsonArrayReader(a, ds);
|
||||
const v: NomsList<Value> = r.readValue();
|
||||
invariant(v instanceof NomsList);
|
||||
const v: List<Value> = r.readValue();
|
||||
invariant(v instanceof List);
|
||||
|
||||
const tr = makeListType(makeUnionType([boolType, numberType, stringType]));
|
||||
assert.isTrue(equals(v.type, tr));
|
||||
@@ -156,8 +157,8 @@ suite('Decode', () => {
|
||||
],
|
||||
];
|
||||
const r = new JsonArrayReader(a, ds);
|
||||
const v: NomsMap<boolean | number, number | string> = r.readValue();
|
||||
invariant(v instanceof NomsMap);
|
||||
const v: Map<boolean | number, number | string> = r.readValue();
|
||||
invariant(v instanceof Map);
|
||||
|
||||
const tr = makeMapType(makeUnionType([boolType, numberType]),
|
||||
makeUnionType([numberType, stringType]));
|
||||
@@ -172,23 +173,23 @@ suite('Decode', () => {
|
||||
[Kind.Number, '0', Kind.Number, '1', Kind.Number, '2']];
|
||||
const r = new JsonArrayReader(a, ds);
|
||||
const v = r.readValue();
|
||||
invariant(v instanceof NomsList);
|
||||
invariant(v instanceof List);
|
||||
|
||||
const l = new NomsList(newListLeafSequence(ds, [0, 1, 2]));
|
||||
const l = new List(newListLeafSequence(ds, [0, 1, 2]));
|
||||
assert.isTrue(equals(l, v));
|
||||
});
|
||||
|
||||
test('read compound list', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const r1 = ds.writeValue(new NomsList(newListLeafSequence(ds, [0])));
|
||||
const r2 = ds.writeValue(new NomsList(newListLeafSequence(ds, [1, 2])));
|
||||
const r3 = ds.writeValue(new NomsList(newListLeafSequence(ds, [3, 4, 5])));
|
||||
const r1 = ds.writeValue(new List(newListLeafSequence(ds, [0])));
|
||||
const r2 = ds.writeValue(new List(newListLeafSequence(ds, [1, 2])));
|
||||
const r3 = ds.writeValue(new List(newListLeafSequence(ds, [3, 4, 5])));
|
||||
const tuples = [
|
||||
new MetaTuple(r1, 1, 1),
|
||||
new MetaTuple(r2, 2, 2),
|
||||
new MetaTuple(r3, 3, 3),
|
||||
];
|
||||
const l: NomsList<number> = new NomsList(newListMetaSequence(ds, tuples));
|
||||
const l: List<number> = new List(newListMetaSequence(ds, tuples));
|
||||
|
||||
const a = [
|
||||
Kind.List, Kind.Number, true, [
|
||||
@@ -199,7 +200,7 @@ suite('Decode', () => {
|
||||
];
|
||||
const r = new JsonArrayReader(a, ds);
|
||||
const v = r.readValue();
|
||||
invariant(v instanceof NomsList);
|
||||
invariant(v instanceof List);
|
||||
assert.isTrue(v.ref.equals(l.ref));
|
||||
});
|
||||
|
||||
@@ -209,10 +210,10 @@ suite('Decode', () => {
|
||||
[NumberKind, "0", NumberKind, "1", NumberKind, "2", NumberKind, "3"]]`);
|
||||
|
||||
const r = new JsonArrayReader(a, ds);
|
||||
const v: NomsMap<number, number> = r.readValue();
|
||||
invariant(v instanceof NomsMap);
|
||||
const v: Map<number, number> = r.readValue();
|
||||
invariant(v instanceof Map);
|
||||
|
||||
const m = new NomsMap(newMapLeafSequence(ds, [{key: 0, value: 1}, {key: 2, value: 3}]));
|
||||
const m = new Map(newMapLeafSequence(ds, [{key: 0, value: 1}, {key: 2, value: 3}]));
|
||||
assert.isTrue(equals(v, m));
|
||||
});
|
||||
|
||||
@@ -227,10 +228,10 @@ suite('Decode', () => {
|
||||
],
|
||||
];
|
||||
const r = new JsonArrayReader(a, ds);
|
||||
const v: NomsMap<RefValue<Value>, number> = r.readValue();
|
||||
invariant(v instanceof NomsMap);
|
||||
const v: Map<RefValue<Value>, number> = r.readValue();
|
||||
invariant(v instanceof Map);
|
||||
|
||||
const m = new NomsMap(newMapLeafSequence(ds, [{key: rv1, value: 2}, {key: rv2, value: 4}]));
|
||||
const m = new Map(newMapLeafSequence(ds, [{key: rv1, value: 2}, {key: rv2, value: 4}]));
|
||||
assert.isTrue(equals(v, m));
|
||||
});
|
||||
|
||||
@@ -239,10 +240,10 @@ suite('Decode', () => {
|
||||
const a = parseJson(`[ValueKind, MapKind, NumberKind, NumberKind, false,
|
||||
[NumberKind, "0", NumberKind, "1", NumberKind, "2", NumberKind, "3"]]`);
|
||||
const r = new JsonArrayReader(a, ds);
|
||||
const v: NomsMap<number, number> = r.readValue();
|
||||
invariant(v instanceof NomsMap);
|
||||
const v: Map<number, number> = r.readValue();
|
||||
invariant(v instanceof Map);
|
||||
|
||||
const m = new NomsMap(newMapLeafSequence(ds, [{key: 0, value: 1}, {key: 2, value: 3}]));
|
||||
const m = new Map(newMapLeafSequence(ds, [{key: 0, value: 1}, {key: 2, value: 3}]));
|
||||
assert.isTrue(equals(v, m));
|
||||
});
|
||||
|
||||
@@ -350,7 +351,7 @@ suite('Decode', () => {
|
||||
|
||||
assertStruct(v, tr.desc, {
|
||||
b: true,
|
||||
l: new NomsList(newListLeafSequence(ds, [0, 1, 2])),
|
||||
l: new List(newListLeafSequence(ds, [0, 1, 2])),
|
||||
s: 'hi',
|
||||
});
|
||||
});
|
||||
@@ -403,8 +404,8 @@ suite('Decode', () => {
|
||||
]`);
|
||||
|
||||
const r = new JsonArrayReader(a, ds);
|
||||
const v: NomsMap<string, Struct> = r.readValue();
|
||||
invariant(v instanceof NomsMap);
|
||||
const v: Map<string, Struct> = r.readValue();
|
||||
invariant(v instanceof Map);
|
||||
|
||||
assert.strictEqual(3, v.size);
|
||||
assertStruct(await v.get('foo'), tr.desc, {b: true, i: 3});
|
||||
@@ -478,7 +479,7 @@ suite('Decode', () => {
|
||||
test('out of line blob', async () => {
|
||||
const chunk = Chunk.fromString('b hi');
|
||||
const blob = decodeNomsValue(chunk, new Database(makeTestingBatchStore()));
|
||||
invariant(blob instanceof NomsBlob);
|
||||
invariant(blob instanceof Blob);
|
||||
const r = await blob.getReader().read();
|
||||
assert.isFalse(r.done);
|
||||
invariant(r.value);
|
||||
@@ -496,7 +497,7 @@ suite('Decode', () => {
|
||||
|
||||
const chunk2 = new Chunk(data);
|
||||
const blob2 = decodeNomsValue(chunk2, new Database(makeTestingBatchStore()));
|
||||
invariant(blob2 instanceof NomsBlob);
|
||||
invariant(blob2 instanceof Blob);
|
||||
const r2 = await blob2.getReader().read();
|
||||
assert.isFalse(r2.done);
|
||||
invariant(r2.value);
|
||||
@@ -510,8 +511,8 @@ suite('Decode', () => {
|
||||
ListKind, BlobKind, false, [BlobKind, false, "%s", BlobKind, false, "%s"]
|
||||
]`, encodeBase64(stringToUint8Array('hello')), encodeBase64(stringToUint8Array('world')));
|
||||
const r = new JsonArrayReader(a, ds);
|
||||
const v: NomsList<NomsBlob> = r.readValue();
|
||||
invariant(v instanceof NomsList);
|
||||
const v: List<Blob> = r.readValue();
|
||||
invariant(v instanceof List);
|
||||
|
||||
assert.strictEqual(2, v.length);
|
||||
const [b1, b2] = [await v.get(0), await v.get(1)];
|
||||
@@ -534,8 +535,8 @@ suite('Decode', () => {
|
||||
]
|
||||
]`, r1.targetRef, r2.targetRef);
|
||||
const r = new JsonArrayReader(a, ds);
|
||||
const v: NomsBlob = r.readValue();
|
||||
invariant(v instanceof NomsBlob);
|
||||
const v: Blob = r.readValue();
|
||||
invariant(v instanceof Blob);
|
||||
|
||||
const reader = v.getReader();
|
||||
assert.deepEqual(await reader.read(), {done: false, value: stringToUint8Array('hi')});
|
||||
@@ -603,7 +604,7 @@ suite('Decode', () => {
|
||||
false, [StringKind, "hi", NumberKind, "42"]]`);
|
||||
const r = new JsonArrayReader(a, ds);
|
||||
const v = r.readValue();
|
||||
const v2 = new NomsList(newListLeafSequence(ds, ['hi', 42]));
|
||||
const v2 = new List(newListLeafSequence(ds, ['hi', 42]));
|
||||
assert.isTrue(equals(v, v2));
|
||||
});
|
||||
|
||||
@@ -612,7 +613,7 @@ suite('Decode', () => {
|
||||
const a = parseJson(`[ListKind, UnionKind, 0, false, []]`);
|
||||
const r = new JsonArrayReader(a, ds);
|
||||
const v = r.readValue();
|
||||
const v2 = new NomsList(newListLeafSequence(ds, []));
|
||||
const v2 = new List(newListLeafSequence(ds, []));
|
||||
assert.isTrue(equals(v, v2));
|
||||
});
|
||||
});
|
||||
|
||||
+14
-14
@@ -1,9 +1,9 @@
|
||||
// @flow
|
||||
|
||||
import {NomsBlob, BlobLeafSequence} from './blob.js';
|
||||
import Blob, {BlobLeafSequence} from './blob.js';
|
||||
import Chunk from './chunk.js';
|
||||
import Ref from './ref.js';
|
||||
import {default as RefValue, constructRefValue} from './ref-value.js';
|
||||
import RefValue, {constructRefValue} from './ref-value.js';
|
||||
import {newStructWithTypeNoValidation} from './struct.js';
|
||||
import type Struct from './struct.js';
|
||||
import type {NomsKind} from './noms-kind.js';
|
||||
@@ -23,9 +23,9 @@ import {
|
||||
import {MetaTuple} from './meta-sequence.js';
|
||||
import {invariant} from './assert.js';
|
||||
import {isPrimitiveKind, Kind} from './noms-kind.js';
|
||||
import {ListLeafSequence, NomsList} from './list.js';
|
||||
import {NomsMap, MapLeafSequence} from './map.js';
|
||||
import {NomsSet, SetLeafSequence} from './set.js';
|
||||
import List, {ListLeafSequence} from './list.js';
|
||||
import Map, {MapLeafSequence} from './map.js';
|
||||
import Set, {SetLeafSequence} from './set.js';
|
||||
import {IndexedMetaSequence, OrderedMetaSequence} from './meta-sequence.js';
|
||||
import type {valueOrPrimitive} from './value.js';
|
||||
import type {ValueReader} from './value-store.js';
|
||||
@@ -215,10 +215,10 @@ export class JsonArrayReader {
|
||||
const isMeta = this.readBool();
|
||||
if (isMeta) {
|
||||
const r2 = new JsonArrayReader(this.readArray(), this._ds);
|
||||
return new NomsBlob(r2.readIndexedMetaSequence(t));
|
||||
return new Blob(r2.readIndexedMetaSequence(t));
|
||||
}
|
||||
|
||||
return new NomsBlob(this.readBlobLeafSequence());
|
||||
return new Blob(this.readBlobLeafSequence());
|
||||
}
|
||||
case Kind.Bool:
|
||||
return this.readBool();
|
||||
@@ -233,17 +233,17 @@ export class JsonArrayReader {
|
||||
const isMeta = this.readBool();
|
||||
const r2 = new JsonArrayReader(this.readArray(), this._ds);
|
||||
if (isMeta) {
|
||||
return new NomsList(r2.readIndexedMetaSequence(t));
|
||||
return new List(r2.readIndexedMetaSequence(t));
|
||||
}
|
||||
return new NomsList(r2.readListLeafSequence(t));
|
||||
return new List(r2.readListLeafSequence(t));
|
||||
}
|
||||
case Kind.Map: {
|
||||
const isMeta = this.readBool();
|
||||
const r2 = new JsonArrayReader(this.readArray(), this._ds);
|
||||
if (isMeta) {
|
||||
return new NomsMap(r2.readOrderedMetaSequence(t));
|
||||
return new Map(r2.readOrderedMetaSequence(t));
|
||||
}
|
||||
return new NomsMap(r2.readMapLeafSequence(t));
|
||||
return new Map(r2.readMapLeafSequence(t));
|
||||
}
|
||||
case Kind.Ref:
|
||||
return this.readRefValue(t);
|
||||
@@ -251,9 +251,9 @@ export class JsonArrayReader {
|
||||
const isMeta = this.readBool();
|
||||
const r2 = new JsonArrayReader(this.readArray(), this._ds);
|
||||
if (isMeta) {
|
||||
return new NomsSet(r2.readOrderedMetaSequence(t));
|
||||
return new Set(r2.readOrderedMetaSequence(t));
|
||||
}
|
||||
return new NomsSet(r2.readSetLeafSequence(t));
|
||||
return new Set(r2.readSetLeafSequence(t));
|
||||
}
|
||||
case Kind.Struct:
|
||||
return this.readStruct(t);
|
||||
@@ -310,7 +310,7 @@ export function decodeNomsValue(chunk: Chunk, vr: ValueReader): valueOrPrimitive
|
||||
return reader.readValue();
|
||||
}
|
||||
case blobTag:
|
||||
return new NomsBlob(new BlobLeafSequence(vr, new Uint8Array(chunk.data.buffer, 2)));
|
||||
return new Blob(new BlobLeafSequence(vr, new Uint8Array(chunk.data.buffer, 2)));
|
||||
default:
|
||||
throw new Error('Not implemented');
|
||||
}
|
||||
|
||||
+31
-31
@@ -24,9 +24,9 @@ import {
|
||||
} from './type.js';
|
||||
import {newListMetaSequence, MetaTuple, newSetMetaSequence} from './meta-sequence.js';
|
||||
import {Kind} from './noms-kind.js';
|
||||
import {newListLeafSequence, NomsList} from './list.js';
|
||||
import {newMapLeafSequence, NomsMap} from './map.js';
|
||||
import {NomsSet, newSetLeafSequence} from './set.js';
|
||||
import List, {newListLeafSequence} from './list.js';
|
||||
import Map, {newMapLeafSequence} from './map.js';
|
||||
import Set, {newSetLeafSequence} from './set.js';
|
||||
import {newBlob} from './blob.js';
|
||||
import Database from './database.js';
|
||||
import type {valueOrPrimitive} from './value.js';
|
||||
@@ -64,7 +64,7 @@ suite('Encode', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const w = new JsonArrayWriter(ds);
|
||||
|
||||
const l = new NomsList(newListLeafSequence(ds, [0, 1, 2, 3]));
|
||||
const l = new List(newListLeafSequence(ds, [0, 1, 2, 3]));
|
||||
w.writeValue(l);
|
||||
assert.deepEqual([Kind.List, Kind.Number, false,
|
||||
[Kind.Number, '0', Kind.Number, '1', Kind.Number, '2', Kind.Number, '3']], w.array);
|
||||
@@ -74,7 +74,7 @@ suite('Encode', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const w = new JsonArrayWriter(ds);
|
||||
|
||||
const l = new NomsList(newListLeafSequence(ds, ['0', 1, '2', true]));
|
||||
const l = new List(newListLeafSequence(ds, ['0', 1, '2', true]));
|
||||
w.writeValue(l);
|
||||
assert.deepEqual([Kind.List, Kind.Union, 3, Kind.Bool, Kind.Number, Kind.String, false, [
|
||||
Kind.String, '0',
|
||||
@@ -88,9 +88,9 @@ suite('Encode', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const w = new JsonArrayWriter(ds);
|
||||
|
||||
const v = new NomsList(newListLeafSequence(ds, [
|
||||
new NomsList(newListLeafSequence(ds, [0])),
|
||||
new NomsList(newListLeafSequence(ds, [1, 2, 3])),
|
||||
const v = new List(newListLeafSequence(ds, [
|
||||
new List(newListLeafSequence(ds, [0])),
|
||||
new List(newListLeafSequence(ds, [1, 2, 3])),
|
||||
]));
|
||||
w.writeValue(v);
|
||||
assert.deepEqual([Kind.List, Kind.List, Kind.Number, false, [
|
||||
@@ -103,7 +103,7 @@ suite('Encode', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const w = new JsonArrayWriter(ds);
|
||||
|
||||
const v = new NomsSet(newSetLeafSequence(ds, [0, 1, 2, 3]));
|
||||
const v = new Set(newSetLeafSequence(ds, [0, 1, 2, 3]));
|
||||
w.writeValue(v);
|
||||
assert.deepEqual([Kind.Set, Kind.Number, false,
|
||||
[Kind.Number, '0', Kind.Number, '1', Kind.Number, '2', Kind.Number, '3']], w.array);
|
||||
@@ -112,15 +112,15 @@ suite('Encode', () => {
|
||||
test('write compound set', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const w = new JsonArrayWriter(ds);
|
||||
const r1 = ds.writeValue(new NomsSet(newSetLeafSequence(ds, [0])));
|
||||
const r2 = ds.writeValue(new NomsSet(newSetLeafSequence(ds, [1, 2])));
|
||||
const r3 = ds.writeValue(new NomsSet(newSetLeafSequence(ds, [3, 4, 5])));
|
||||
const r1 = ds.writeValue(new Set(newSetLeafSequence(ds, [0])));
|
||||
const r2 = ds.writeValue(new Set(newSetLeafSequence(ds, [1, 2])));
|
||||
const r3 = ds.writeValue(new Set(newSetLeafSequence(ds, [3, 4, 5])));
|
||||
const tuples = [
|
||||
new MetaTuple(r1, 0, 1),
|
||||
new MetaTuple(r2, 2, 2),
|
||||
new MetaTuple(r3, 5, 3),
|
||||
];
|
||||
const l = new NomsSet(newSetMetaSequence(ds, tuples));
|
||||
const l = new Set(newSetMetaSequence(ds, tuples));
|
||||
|
||||
w.writeValue(l);
|
||||
assert.deepEqual([
|
||||
@@ -136,9 +136,9 @@ suite('Encode', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const w = new JsonArrayWriter(ds);
|
||||
|
||||
const v = new NomsSet(newSetLeafSequence(ds, [
|
||||
new NomsSet(newSetLeafSequence(ds, [0])),
|
||||
new NomsSet(newSetLeafSequence(ds, [1, 2, 3])),
|
||||
const v = new Set(newSetLeafSequence(ds, [
|
||||
new Set(newSetLeafSequence(ds, [0])),
|
||||
new Set(newSetLeafSequence(ds, [1, 2, 3])),
|
||||
]));
|
||||
|
||||
w.writeValue(v);
|
||||
@@ -152,7 +152,7 @@ suite('Encode', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const w = new JsonArrayWriter(ds);
|
||||
|
||||
const v = new NomsMap(newMapLeafSequence(ds, [{key: 'a', value: false},
|
||||
const v = new Map(newMapLeafSequence(ds, [{key: 'a', value: false},
|
||||
{key:'b', value:true}]));
|
||||
w.writeValue(v);
|
||||
assert.deepEqual([Kind.Map, Kind.String, Kind.Bool, false,
|
||||
@@ -164,9 +164,9 @@ suite('Encode', () => {
|
||||
const w = new JsonArrayWriter(ds);
|
||||
|
||||
// Map<Map<String, Number>, Set<Bool>>({{'a': 0}: {true}})
|
||||
const s = new NomsSet(newSetLeafSequence(ds, [true]));
|
||||
const m1 = new NomsMap(newMapLeafSequence(ds, [{key: 'a', value: 0}]));
|
||||
const v = new NomsMap(newMapLeafSequence(ds, [{key: m1, value: s}]));
|
||||
const s = new Set(newSetLeafSequence(ds, [true]));
|
||||
const m1 = new Map(newMapLeafSequence(ds, [{key: 'a', value: 0}]));
|
||||
const v = new Map(newMapLeafSequence(ds, [{key: m1, value: s}]));
|
||||
w.writeValue(v);
|
||||
assert.deepEqual([Kind.Map,
|
||||
Kind.Map, Kind.String, Kind.Number,
|
||||
@@ -199,12 +199,12 @@ suite('Encode', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
let w = new JsonArrayWriter(ds);
|
||||
|
||||
let v = newStruct('S', {l: new NomsList(newListLeafSequence(ds, ['a', 'b']))});
|
||||
let v = newStruct('S', {l: new List(newListLeafSequence(ds, ['a', 'b']))});
|
||||
w.writeValue(v);
|
||||
assert.deepEqual([Kind.Struct, 'S', ['l', Kind.List, Kind.String],
|
||||
Kind.List, Kind.String, false, [Kind.String, 'a', Kind.String, 'b']], w.array);
|
||||
|
||||
v = newStruct('S', {l: new NomsList(newListLeafSequence(ds, []))});
|
||||
v = newStruct('S', {l: new List(newListLeafSequence(ds, []))});
|
||||
w = new JsonArrayWriter(ds);
|
||||
w.writeValue(v);
|
||||
assert.deepEqual([Kind.Struct, 'S', ['l', Kind.List, Kind.Union, 0],
|
||||
@@ -225,15 +225,15 @@ suite('Encode', () => {
|
||||
test('write compound list', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const w = new JsonArrayWriter(ds);
|
||||
const r1 = ds.writeValue(new NomsList(newListLeafSequence(ds, [0])));
|
||||
const r2 = ds.writeValue(new NomsList(newListLeafSequence(ds, [1, 2])));
|
||||
const r3 = ds.writeValue(new NomsList(newListLeafSequence(ds, [3, 4, 5])));
|
||||
const r1 = ds.writeValue(new List(newListLeafSequence(ds, [0])));
|
||||
const r2 = ds.writeValue(new List(newListLeafSequence(ds, [1, 2])));
|
||||
const r3 = ds.writeValue(new List(newListLeafSequence(ds, [3, 4, 5])));
|
||||
const tuples = [
|
||||
new MetaTuple(r1, 1, 1),
|
||||
new MetaTuple(r2, 2, 2),
|
||||
new MetaTuple(r3, 3, 3),
|
||||
];
|
||||
const l = new NomsList(newListMetaSequence(ds, tuples));
|
||||
const l = new List(newListMetaSequence(ds, tuples));
|
||||
|
||||
w.writeValue(l);
|
||||
assert.deepEqual([
|
||||
@@ -248,13 +248,13 @@ suite('Encode', () => {
|
||||
test('write compound set with bool', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const w = new JsonArrayWriter(ds);
|
||||
const r1 = ds.writeValue(new NomsSet(newSetLeafSequence(ds, [true])));
|
||||
const r2 = ds.writeValue(new NomsSet(newSetLeafSequence(ds, [false])));
|
||||
const r1 = ds.writeValue(new Set(newSetLeafSequence(ds, [true])));
|
||||
const r2 = ds.writeValue(new Set(newSetLeafSequence(ds, [false])));
|
||||
const tuples = [
|
||||
new MetaTuple(r1, true, 1),
|
||||
new MetaTuple(r2, false, 1),
|
||||
];
|
||||
const l = new NomsSet(newSetMetaSequence(ds, tuples));
|
||||
const l = new Set(newSetMetaSequence(ds, tuples));
|
||||
|
||||
w.writeValue(l);
|
||||
assert.deepEqual([
|
||||
@@ -350,7 +350,7 @@ suite('Encode', () => {
|
||||
test('write union list', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const w = new JsonArrayWriter(ds);
|
||||
const v = new NomsList(newListLeafSequence(ds, ['hi', 42]));
|
||||
const v = new List(newListLeafSequence(ds, ['hi', 42]));
|
||||
w.writeValue(v);
|
||||
assert.deepEqual([Kind.List, Kind.Union, 2, Kind.Number, Kind.String,
|
||||
false, [Kind.String, 'hi', Kind.Number, '42']], w.array);
|
||||
@@ -359,7 +359,7 @@ suite('Encode', () => {
|
||||
test('write empty union list', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const w = new JsonArrayWriter(ds);
|
||||
const v = new NomsList(newListLeafSequence(ds, []));
|
||||
const v = new List(newListLeafSequence(ds, []));
|
||||
w.writeValue(v);
|
||||
assert.deepEqual([Kind.List, Kind.Union, 0, false, []], w.array);
|
||||
});
|
||||
|
||||
+10
-10
@@ -2,19 +2,19 @@
|
||||
|
||||
import Chunk from './chunk.js';
|
||||
import RefValue from './ref-value.js';
|
||||
import {default as Struct, StructMirror} from './struct.js';
|
||||
import Struct, {StructMirror} from './struct.js';
|
||||
import type {NomsKind} from './noms-kind.js';
|
||||
import {encode as encodeBase64} from './base64.js';
|
||||
import {StructDesc, Type, getTypeOfValue} from './type.js';
|
||||
import {MetaTuple} from './meta-sequence.js';
|
||||
import {invariant} from './assert.js';
|
||||
import {isPrimitiveKind, Kind} from './noms-kind.js';
|
||||
import {ListLeafSequence, NomsList} from './list.js';
|
||||
import {MapLeafSequence, NomsMap} from './map.js';
|
||||
import {NomsSet, SetLeafSequence} from './set.js';
|
||||
import List, {ListLeafSequence} from './list.js';
|
||||
import Map, {MapLeafSequence} from './map.js';
|
||||
import Set, {SetLeafSequence} from './set.js';
|
||||
import {Sequence} from './sequence.js';
|
||||
import {setEncodeNomsValue} from './get-ref.js';
|
||||
import {NomsBlob, BlobLeafSequence} from './blob.js';
|
||||
import Blob, {BlobLeafSequence} from './blob.js';
|
||||
import {describeTypeOfValue} from './encode-human-readable.js';
|
||||
import type {primitive} from './primitives.js';
|
||||
import type {valueOrPrimitive} from './value.js';
|
||||
@@ -122,7 +122,7 @@ export class JsonArrayWriter {
|
||||
this.writeType(t, []);
|
||||
switch (t.kind) {
|
||||
case Kind.Blob: {
|
||||
invariant(v instanceof NomsBlob,
|
||||
invariant(v instanceof Blob,
|
||||
() => `Failed to write Blob. Invalid type: ${describeTypeOfValue(v)}`);
|
||||
const sequence = v.sequence;
|
||||
if (this.maybeWriteMetaSequence(sequence)) {
|
||||
@@ -149,7 +149,7 @@ export class JsonArrayWriter {
|
||||
this.writeFloat(v);
|
||||
break;
|
||||
case Kind.List: {
|
||||
invariant(v instanceof NomsList,
|
||||
invariant(v instanceof List,
|
||||
() => `Failed to write List. Invalid type: ${describeTypeOfValue(v)}`);
|
||||
const sequence = v.sequence;
|
||||
if (this.maybeWriteMetaSequence(sequence)) {
|
||||
@@ -163,7 +163,7 @@ export class JsonArrayWriter {
|
||||
break;
|
||||
}
|
||||
case Kind.Map: {
|
||||
invariant(v instanceof NomsMap,
|
||||
invariant(v instanceof Map,
|
||||
() => `Failed to write Map. Invalid type: ${describeTypeOfValue(v)}`);
|
||||
const sequence = v.sequence;
|
||||
if (this.maybeWriteMetaSequence(sequence)) {
|
||||
@@ -186,7 +186,7 @@ export class JsonArrayWriter {
|
||||
break;
|
||||
}
|
||||
case Kind.Set: {
|
||||
invariant(v instanceof NomsSet,
|
||||
invariant(v instanceof Set,
|
||||
() => `Failed to write Set. Invalid type: ${describeTypeOfValue(v)}`);
|
||||
const sequence = v.sequence;
|
||||
if (this.maybeWriteMetaSequence(sequence)) {
|
||||
@@ -282,7 +282,7 @@ function encodeTopLevelBlob(sequence: BlobLeafSequence): Chunk {
|
||||
export function encodeNomsValue(v: valueOrPrimitive, vw: ?ValueWriter): Chunk {
|
||||
const t = getTypeOfValue(v);
|
||||
if (t.kind === Kind.Blob) {
|
||||
invariant(v instanceof NomsBlob);
|
||||
invariant(v instanceof Blob);
|
||||
const sequence = v.sequence;
|
||||
if (!sequence.isMeta) {
|
||||
invariant(sequence instanceof BlobLeafSequence);
|
||||
|
||||
+19
-19
@@ -26,12 +26,12 @@ import {
|
||||
} from './test-util.js';
|
||||
import {newListMetaSequence, MetaTuple} from './meta-sequence.js';
|
||||
import {invariant} from './assert.js';
|
||||
import {newListLeafSequence, newList, NomsList} from './list.js';
|
||||
import List, {newListLeafSequence, newList} from './list.js';
|
||||
|
||||
const testListSize = 5000;
|
||||
const listOfNRef = 'sha1-aa1605484d993e89dbc0431acb9f2478282f9d94';
|
||||
|
||||
async function assertToJS(list: NomsList, nums: Array<any>, start: number = 0,
|
||||
async function assertToJS(list: List, nums: Array<any>, start: number = 0,
|
||||
end: number = nums.length): Promise<void> {
|
||||
const jsArray = await list.toJS(start, end);
|
||||
const expect = nums.slice(start, end);
|
||||
@@ -43,7 +43,7 @@ async function assertToJS(list: NomsList, nums: Array<any>, start: number = 0,
|
||||
|
||||
suite('List', () => {
|
||||
|
||||
async function testPrependChunkDiff(nums: Array<any>, list: NomsList, expectCount: number):
|
||||
async function testPrependChunkDiff(nums: Array<any>, list: List, expectCount: number):
|
||||
Promise<void> {
|
||||
const nn = new Array(nums.length + 1);
|
||||
nn[0] = 0;
|
||||
@@ -55,7 +55,7 @@ suite('List', () => {
|
||||
assert.strictEqual(expectCount, chunkDiffCount(list, v2));
|
||||
}
|
||||
|
||||
async function testAppendChunkDiff(nums: Array<any>, list: NomsList, expectCount: number):
|
||||
async function testAppendChunkDiff(nums: Array<any>, list: List, expectCount: number):
|
||||
Promise<void> {
|
||||
const nn = new Array(nums.length + 1);
|
||||
nn[0] = 0;
|
||||
@@ -68,7 +68,7 @@ suite('List', () => {
|
||||
assert.strictEqual(expectCount, chunkDiffCount(list, v2));
|
||||
}
|
||||
|
||||
async function testToJS(expect: Array<any>, list: NomsList): Promise<void> {
|
||||
async function testToJS(expect: Array<any>, list: List): Promise<void> {
|
||||
const length = expect.length;
|
||||
let start = 0;
|
||||
|
||||
@@ -79,7 +79,7 @@ suite('List', () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function testGet(nums: Array<any>, list: NomsList): Promise<void> {
|
||||
async function testGet(nums: Array<any>, list: List): Promise<void> {
|
||||
const incr = Math.round(nums.length / 256); // test 256 indices
|
||||
|
||||
for (let i = 0; i < nums.length; i += incr) {
|
||||
@@ -87,7 +87,7 @@ suite('List', () => {
|
||||
}
|
||||
}
|
||||
|
||||
async function testForEach(nums: Array<any>, list: NomsList): Promise<void> {
|
||||
async function testForEach(nums: Array<any>, list: List): Promise<void> {
|
||||
const out = [];
|
||||
await list.forEach(v => {
|
||||
out.push(v);
|
||||
@@ -203,7 +203,7 @@ suite('List', () => {
|
||||
const outNums = await s2.toJS();
|
||||
assert.deepEqual(nums, outNums);
|
||||
|
||||
invariant(s2 instanceof NomsList);
|
||||
invariant(s2 instanceof List);
|
||||
const s3 = await s2.splice(testListSize - 1, 1);
|
||||
const outNums2 = await s3.toJS();
|
||||
nums.splice(testListSize - 1, 1);
|
||||
@@ -214,7 +214,7 @@ suite('List', () => {
|
||||
suite('ListLeafSequence', () => {
|
||||
test('Empty list isEmpty', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const newList = items => new NomsList(newListLeafSequence(ds, items));
|
||||
const newList = items => new List(newListLeafSequence(ds, items));
|
||||
assert.isTrue(newList([]).isEmpty());
|
||||
});
|
||||
|
||||
@@ -222,7 +222,7 @@ suite('ListLeafSequence', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
|
||||
const test = async items => {
|
||||
const l = new NomsList(newListLeafSequence(ds, items));
|
||||
const l = new List(newListLeafSequence(ds, items));
|
||||
assert.deepEqual(items, await flatten(l.iterator()));
|
||||
assert.deepEqual(items, await flattenParallel(l.iterator(), items.length));
|
||||
};
|
||||
@@ -236,7 +236,7 @@ suite('ListLeafSequence', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
|
||||
const test = async items => {
|
||||
const l = new NomsList(newListLeafSequence(ds, items));
|
||||
const l = new List(newListLeafSequence(ds, items));
|
||||
for (let i = 0; i <= items.length; i++) {
|
||||
const slice = items.slice(i);
|
||||
assert.deepEqual(slice, await flatten(l.iteratorAt(i)));
|
||||
@@ -251,25 +251,25 @@ suite('ListLeafSequence', () => {
|
||||
});
|
||||
|
||||
suite('CompoundList', () => {
|
||||
function build(): NomsList {
|
||||
function build(): List {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const l1 = new NomsList(newListLeafSequence(ds, ['a', 'b']));
|
||||
const l1 = new List(newListLeafSequence(ds, ['a', 'b']));
|
||||
const r1 = ds.writeValue(l1);
|
||||
const l2 = new NomsList(newListLeafSequence(ds, ['e', 'f']));
|
||||
const l2 = new List(newListLeafSequence(ds, ['e', 'f']));
|
||||
const r2 = ds.writeValue(l2);
|
||||
const l3 = new NomsList(newListLeafSequence(ds, ['h', 'i']));
|
||||
const l3 = new List(newListLeafSequence(ds, ['h', 'i']));
|
||||
const r3 = ds.writeValue(l3);
|
||||
const l4 = new NomsList(newListLeafSequence(ds, ['m', 'n']));
|
||||
const l4 = new List(newListLeafSequence(ds, ['m', 'n']));
|
||||
const r4 = ds.writeValue(l4);
|
||||
|
||||
const m1 = new NomsList(newListMetaSequence(ds, [new MetaTuple(r1, 2, 2),
|
||||
const m1 = new List(newListMetaSequence(ds, [new MetaTuple(r1, 2, 2),
|
||||
new MetaTuple(r2, 2, 2)]));
|
||||
const rm1 = ds.writeValue(m1);
|
||||
const m2 = new NomsList(newListMetaSequence(ds, [new MetaTuple(r3, 2, 2),
|
||||
const m2 = new List(newListMetaSequence(ds, [new MetaTuple(r3, 2, 2),
|
||||
new MetaTuple(r4, 2, 2)]));
|
||||
const rm2 = ds.writeValue(m2);
|
||||
|
||||
const l = new NomsList(newListMetaSequence(ds, [new MetaTuple(rm1, 4, 4),
|
||||
const l = new List(newListMetaSequence(ds, [new MetaTuple(rm1, 4, 4),
|
||||
new MetaTuple(rm2, 4, 4)]));
|
||||
return l;
|
||||
}
|
||||
|
||||
+8
-8
@@ -26,7 +26,7 @@ const listPattern = ((1 << 6) | 0) - 1;
|
||||
|
||||
function newListLeafChunkFn<T: valueOrPrimitive>(vr: ?ValueReader): makeChunkFn {
|
||||
return (items: Array<T>) => {
|
||||
const list = new NomsList(newListLeafSequence(vr, items));
|
||||
const list = new List(newListLeafSequence(vr, items));
|
||||
const mt = new MetaTuple(new RefValue(list), items.length, items.length, list);
|
||||
return [mt, list];
|
||||
};
|
||||
@@ -38,21 +38,21 @@ function newListLeafBoundaryChecker<T: valueOrPrimitive>(): BoundaryChecker<T> {
|
||||
);
|
||||
}
|
||||
|
||||
export function newList<T: valueOrPrimitive>(values: Array<T>): Promise<NomsList<T>> {
|
||||
export function newList<T: valueOrPrimitive>(values: Array<T>): Promise<List<T>> {
|
||||
return chunkSequence(null, values, 0, newListLeafChunkFn(null),
|
||||
newIndexedMetaSequenceChunkFn(Kind.List, null),
|
||||
newListLeafBoundaryChecker(),
|
||||
newIndexedMetaSequenceBoundaryChecker);
|
||||
}
|
||||
|
||||
export class NomsList<T: valueOrPrimitive> extends Collection<IndexedSequence> {
|
||||
export default class List<T: valueOrPrimitive> extends Collection<IndexedSequence> {
|
||||
async get(idx: number): Promise<T> {
|
||||
// TODO (when |length| works) invariant(idx < this.length, idx + ' >= ' + this.length);
|
||||
const cursor = await this.sequence.newCursorAt(idx);
|
||||
return cursor.getCurrent();
|
||||
}
|
||||
|
||||
splice(idx: number, deleteCount: number, ...insert: Array<T>): Promise<NomsList<T>> {
|
||||
splice(idx: number, deleteCount: number, ...insert: Array<T>): Promise<List<T>> {
|
||||
const vr = this.sequence.vr;
|
||||
return this.sequence.newCursorAt(idx).then(cursor =>
|
||||
chunkSequence(cursor, insert, deleteCount, newListLeafChunkFn(vr),
|
||||
@@ -61,15 +61,15 @@ export class NomsList<T: valueOrPrimitive> extends Collection<IndexedSequence> {
|
||||
newIndexedMetaSequenceBoundaryChecker));
|
||||
}
|
||||
|
||||
insert(idx: number, ...values: Array<T>): Promise<NomsList<T>> {
|
||||
insert(idx: number, ...values: Array<T>): Promise<List<T>> {
|
||||
return this.splice(idx, 0, ...values);
|
||||
}
|
||||
|
||||
remove(start: number, end: number): Promise<NomsList<T>> {
|
||||
remove(start: number, end: number): Promise<List<T>> {
|
||||
return this.splice(start, end - start);
|
||||
}
|
||||
|
||||
append(...values: Array<T>): Promise<NomsList<T>> {
|
||||
append(...values: Array<T>): Promise<List<T>> {
|
||||
return this.splice(this.length, 0, ...values);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ export class NomsList<T: valueOrPrimitive> extends Collection<IndexedSequence> {
|
||||
return new IndexedSequenceIterator(this.sequence.newCursorAt(i));
|
||||
}
|
||||
|
||||
diff(last: NomsList<T>, loadLimit: number = -1): Promise<Array<Splice>> {
|
||||
diff(last: List<T>, loadLimit: number = -1): Promise<Array<Splice>> {
|
||||
invariant(equals(this.type, last.type));
|
||||
|
||||
if (equals(this, last)) {
|
||||
|
||||
+19
-19
@@ -8,11 +8,11 @@ import MemoryStore from './memory-store.js';
|
||||
import RefValue from './ref-value.js';
|
||||
import BatchStore from './batch-store.js';
|
||||
import {BatchStoreAdaptorDelegate, makeTestingBatchStore} from './batch-store-adaptor.js';
|
||||
import {newStruct, default as Struct} from './struct.js';
|
||||
import Struct, {newStruct} from './struct.js';
|
||||
import {flatten, flattenParallel, deriveCollectionHeight} from './test-util.js';
|
||||
import {invariant} from './assert.js';
|
||||
import Chunk from './chunk.js';
|
||||
import {newMapLeafSequence, newMap, NomsMap} from './map.js';
|
||||
import Map, {newMapLeafSequence, newMap} from './map.js';
|
||||
import {MetaTuple, newMapMetaSequence} from './meta-sequence.js';
|
||||
import Ref from './ref.js';
|
||||
import type {ValueReadWriter} from './value-store.js';
|
||||
@@ -165,7 +165,7 @@ suite('BuildMap', () => {
|
||||
assert.deepEqual(kvs, outKvs);
|
||||
assert.strictEqual(testMapSize, m2.size);
|
||||
|
||||
invariant(m2 instanceof NomsMap);
|
||||
invariant(m2 instanceof Map);
|
||||
const m3 = await m2.remove(testMapSize - 1);
|
||||
const outKvs2 = [];
|
||||
await m3.forEach((v, k) => outKvs2.push(k, v));
|
||||
@@ -239,7 +239,7 @@ suite('BuildMap', () => {
|
||||
assertEqualVal(k, v);
|
||||
}
|
||||
|
||||
invariant(m2 instanceof NomsMap);
|
||||
invariant(m2 instanceof Map);
|
||||
const m3 = await m2.remove(sortedKeys[testMapSize - 1]); // removes struct
|
||||
const outVals2 = [];
|
||||
const outKeys2 = [];
|
||||
@@ -263,7 +263,7 @@ suite('BuildMap', () => {
|
||||
suite('MapLeaf', () => {
|
||||
test('isEmpty/size', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const newMap = entries => new NomsMap(newMapLeafSequence(ds, entries));
|
||||
const newMap = entries => new Map(newMapLeafSequence(ds, entries));
|
||||
let m = newMap([]);
|
||||
assert.isTrue(m.isEmpty());
|
||||
assert.strictEqual(0, m.size);
|
||||
@@ -274,7 +274,7 @@ suite('MapLeaf', () => {
|
||||
|
||||
test('has', async () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const m = new NomsMap(
|
||||
const m = new Map(
|
||||
newMapLeafSequence(ds, [{key: 'a', value: false}, {key: 'k', value: true}]));
|
||||
assert.isTrue(await m.has('a'));
|
||||
assert.isFalse(await m.has('b'));
|
||||
@@ -284,7 +284,7 @@ suite('MapLeaf', () => {
|
||||
|
||||
test('first/last/get', async () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const m = new NomsMap(
|
||||
const m = new Map(
|
||||
newMapLeafSequence(ds, [{key: 'a', value: 4}, {key: 'k', value: 8}]));
|
||||
|
||||
assert.deepEqual(['a', 4], await m.first());
|
||||
@@ -298,7 +298,7 @@ suite('MapLeaf', () => {
|
||||
|
||||
test('forEach', async () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const m = new NomsMap(
|
||||
const m = new Map(
|
||||
newMapLeafSequence(ds, [{key: 'a', value: 4}, {key: 'k', value: 8}]));
|
||||
|
||||
const kv = [];
|
||||
@@ -310,7 +310,7 @@ suite('MapLeaf', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
|
||||
const test = async entries => {
|
||||
const m = new NomsMap(newMapLeafSequence(ds, entries));
|
||||
const m = new Map(newMapLeafSequence(ds, entries));
|
||||
assert.deepEqual(entries, await flatten(m.iterator()));
|
||||
assert.deepEqual(entries, await flattenParallel(m.iterator(), entries.length));
|
||||
};
|
||||
@@ -322,7 +322,7 @@ suite('MapLeaf', () => {
|
||||
|
||||
test('LONG: iteratorAt', async () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const build = entries => new NomsMap(newMapLeafSequence(ds, entries));
|
||||
const build = entries => new Map(newMapLeafSequence(ds, entries));
|
||||
|
||||
assert.deepEqual([], await flatten(build([]).iteratorAt('a')));
|
||||
|
||||
@@ -349,7 +349,7 @@ suite('MapLeaf', () => {
|
||||
const r2 = ds.writeValue(true);
|
||||
const r3 = ds.writeValue('b');
|
||||
const r4 = ds.writeValue(false);
|
||||
const m = new NomsMap(
|
||||
const m = new Map(
|
||||
newMapLeafSequence(ds, [{key: r1, value: r2}, {key: r3, value: r4}]));
|
||||
assert.strictEqual(4, m.chunks.length);
|
||||
assert.isTrue(equals(r1, m.chunks[0]));
|
||||
@@ -361,28 +361,28 @@ suite('MapLeaf', () => {
|
||||
});
|
||||
|
||||
suite('CompoundMap', () => {
|
||||
function build(vwr: ValueReadWriter): Array<NomsMap> {
|
||||
const l1 = new NomsMap(newMapLeafSequence(vwr, [{key: 'a', value: false},
|
||||
function build(vwr: ValueReadWriter): Array<Map> {
|
||||
const l1 = new Map(newMapLeafSequence(vwr, [{key: 'a', value: false},
|
||||
{key:'b', value:false}]));
|
||||
const r1 = vwr.writeValue(l1);
|
||||
const l2 = new NomsMap(newMapLeafSequence(vwr, [{key: 'e', value: true},
|
||||
const l2 = new Map(newMapLeafSequence(vwr, [{key: 'e', value: true},
|
||||
{key:'f', value:true}]));
|
||||
const r2 = vwr.writeValue(l2);
|
||||
const l3 = new NomsMap(newMapLeafSequence(vwr, [{key: 'h', value: false},
|
||||
const l3 = new Map(newMapLeafSequence(vwr, [{key: 'h', value: false},
|
||||
{key:'i', value:true}]));
|
||||
const r3 = vwr.writeValue(l3);
|
||||
const l4 = new NomsMap(newMapLeafSequence(vwr, [{key: 'm', value: true},
|
||||
const l4 = new Map(newMapLeafSequence(vwr, [{key: 'm', value: true},
|
||||
{key:'n', value:false}]));
|
||||
const r4 = vwr.writeValue(l4);
|
||||
|
||||
const m1 = new NomsMap(newMapMetaSequence(vwr, [new MetaTuple(r1, 'b', 2),
|
||||
const m1 = new Map(newMapMetaSequence(vwr, [new MetaTuple(r1, 'b', 2),
|
||||
new MetaTuple(r2, 'f', 2)]));
|
||||
const rm1 = vwr.writeValue(m1);
|
||||
const m2 = new NomsMap(newMapMetaSequence(vwr, [new MetaTuple(r3, 'i', 2),
|
||||
const m2 = new Map(newMapMetaSequence(vwr, [new MetaTuple(r3, 'i', 2),
|
||||
new MetaTuple(r4, 'n', 2)]));
|
||||
const rm2 = vwr.writeValue(m2);
|
||||
|
||||
const c = new NomsMap(newMapMetaSequence(vwr, [new MetaTuple(rm1, 'f', 4),
|
||||
const c = new Map(newMapMetaSequence(vwr, [new MetaTuple(rm1, 'f', 4),
|
||||
new MetaTuple(rm2, 'n', 4)]));
|
||||
return [c, m1, m2];
|
||||
}
|
||||
|
||||
+8
-7
@@ -39,7 +39,7 @@ function newMapLeafChunkFn<K: valueOrPrimitive, V: valueOrPrimitive>(vr: ?ValueR
|
||||
}
|
||||
}
|
||||
|
||||
const nm = new NomsMap(newMapLeafSequence(vr, items));
|
||||
const nm = new Map(newMapLeafSequence(vr, items));
|
||||
const mt = new MetaTuple(new RefValue(nm), indexValue, items.length, nm);
|
||||
return [mt, nm];
|
||||
};
|
||||
@@ -86,14 +86,15 @@ function buildMapData<K: valueOrPrimitive, V: valueOrPrimitive>(kvs: Array<K | V
|
||||
}
|
||||
|
||||
export function newMap<K: valueOrPrimitive, V: valueOrPrimitive>(kvs: Array<K | V>):
|
||||
Promise<NomsMap<K, V>> {
|
||||
Promise<Map<K, V>> {
|
||||
return chunkSequence(null, buildMapData(kvs), 0, newMapLeafChunkFn(null),
|
||||
newOrderedMetaSequenceChunkFn(Kind.Map, null),
|
||||
newMapLeafBoundaryChecker(),
|
||||
newOrderedMetaSequenceBoundaryChecker);
|
||||
}
|
||||
|
||||
export class NomsMap<K: valueOrPrimitive, V: valueOrPrimitive> extends Collection<OrderedSequence> {
|
||||
export default class Map<K: valueOrPrimitive, V: valueOrPrimitive> extends
|
||||
Collection<OrderedSequence> {
|
||||
async has(key: K): Promise<boolean> {
|
||||
const cursor = await this.sequence.newCursorAt(key);
|
||||
return cursor.valid && equals(cursor.getCurrentKey(), key);
|
||||
@@ -144,7 +145,7 @@ export class NomsMap<K: valueOrPrimitive, V: valueOrPrimitive> extends Collectio
|
||||
}
|
||||
|
||||
_splice(cursor: OrderedSequenceCursor, insert: Array<MapEntry<K, V>>, remove: number):
|
||||
Promise<NomsMap<K, V>> {
|
||||
Promise<Map<K, V>> {
|
||||
const vr = this.sequence.vr;
|
||||
return chunkSequence(cursor, insert, remove, newMapLeafChunkFn(vr),
|
||||
newOrderedMetaSequenceChunkFn(Kind.Map, vr),
|
||||
@@ -152,7 +153,7 @@ export class NomsMap<K: valueOrPrimitive, V: valueOrPrimitive> extends Collectio
|
||||
newOrderedMetaSequenceBoundaryChecker);
|
||||
}
|
||||
|
||||
async set(key: K, value: V): Promise<NomsMap<K, V>> {
|
||||
async set(key: K, value: V): Promise<Map<K, V>> {
|
||||
let remove = 0;
|
||||
const cursor = await this.sequence.newCursorAt(key, true);
|
||||
if (cursor.valid && equals(cursor.getCurrentKey(), key)) {
|
||||
@@ -167,7 +168,7 @@ export class NomsMap<K: valueOrPrimitive, V: valueOrPrimitive> extends Collectio
|
||||
return this._splice(cursor, [{key: key, value: value}], remove);
|
||||
}
|
||||
|
||||
async remove(key: K): Promise<NomsMap<K, V>> {
|
||||
async remove(key: K): Promise<Map<K, V>> {
|
||||
const cursor = await this.sequence.newCursorAt(key);
|
||||
if (cursor.valid && equals(cursor.getCurrentKey(), key)) {
|
||||
return this._splice(cursor, [], 1);
|
||||
@@ -183,7 +184,7 @@ export class NomsMap<K: valueOrPrimitive, V: valueOrPrimitive> extends Collectio
|
||||
/**
|
||||
* Returns a 3-tuple [added, removed, modified] sorted by keys.
|
||||
*/
|
||||
diff(from: NomsMap<K, V>): Promise<[Array<K>, Array<K>, Array<K>]> {
|
||||
diff(from: Map<K, V>): Promise<[Array<K>, Array<K>, Array<K>]> {
|
||||
return diff(from.sequence, this.sequence);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,19 +5,19 @@ import {suite, test} from 'mocha';
|
||||
|
||||
import {makeTestingBatchStore} from './batch-store-adaptor.js';
|
||||
import Database from './database.js';
|
||||
import {newListLeafSequence, NomsList} from './list.js';
|
||||
import List, {newListLeafSequence} from './list.js';
|
||||
import {MetaTuple, newOrderedMetaSequenceChunkFn, newIndexedMetaSequenceChunkFn,} from
|
||||
'./meta-sequence.js';
|
||||
import RefValue from './ref-value.js';
|
||||
import {newSetLeafSequence, NomsSet} from './set.js';
|
||||
import Set, {newSetLeafSequence} from './set.js';
|
||||
import {Kind} from './noms-kind.js';
|
||||
|
||||
suite('MetaSequence', () => {
|
||||
test('calculate ordered sequence MetaTuple height', async () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
|
||||
const set1 = new NomsSet(newSetLeafSequence(ds, ['bar', 'baz']));
|
||||
const set2 = new NomsSet(newSetLeafSequence(ds, ['foo', 'qux', 'zoo']));
|
||||
const set1 = new Set(newSetLeafSequence(ds, ['bar', 'baz']));
|
||||
const set2 = new Set(newSetLeafSequence(ds, ['foo', 'qux', 'zoo']));
|
||||
const mt1 = new MetaTuple(new RefValue(set1), 'baz', 2, set1);
|
||||
const mt2 = new MetaTuple(new RefValue(set2), 'zoo', 3, set2);
|
||||
|
||||
@@ -36,8 +36,8 @@ suite('MetaSequence', () => {
|
||||
test('calculate indexed sequence MetaTuple height', async () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
|
||||
const list1 = new NomsList(newListLeafSequence(ds, ['bar', 'baz']));
|
||||
const list2 = new NomsList(newListLeafSequence(ds, ['foo', 'qux', 'zoo']));
|
||||
const list1 = new List(newListLeafSequence(ds, ['bar', 'baz']));
|
||||
const list2 = new List(newListLeafSequence(ds, ['foo', 'qux', 'zoo']));
|
||||
const mt1 = new MetaTuple(new RefValue(list1), 2, 2, list1);
|
||||
const mt2 = new MetaTuple(new RefValue(list2), 3, 3, list2);
|
||||
|
||||
|
||||
@@ -15,10 +15,10 @@ import RefValue from './ref-value.js';
|
||||
import {Sequence} from './sequence.js';
|
||||
import {Kind} from './noms-kind.js';
|
||||
import type {NomsKind} from './noms-kind.js';
|
||||
import {NomsList} from './list.js';
|
||||
import {NomsMap} from './map.js';
|
||||
import {NomsSet} from './set.js';
|
||||
import {NomsBlob} from './blob.js';
|
||||
import List from './list.js';
|
||||
import Map from './map.js';
|
||||
import Set from './set.js';
|
||||
import Blob from './blob.js';
|
||||
import {equals} from './compare.js';
|
||||
|
||||
export type MetaSequence = Sequence<MetaTuple>;
|
||||
@@ -202,11 +202,11 @@ export function newOrderedMetaSequenceChunkFn(kind: NomsKind, vr: ?ValueReader):
|
||||
let col: Collection;
|
||||
if (kind === Kind.Map) {
|
||||
const metaSeq = newMapMetaSequence(vr, tuples);
|
||||
col = new NomsMap(metaSeq);
|
||||
col = new Map(metaSeq);
|
||||
} else {
|
||||
invariant(kind === Kind.Set);
|
||||
const metaSeq = newSetMetaSequence(vr, tuples);
|
||||
col = new NomsSet(metaSeq);
|
||||
col = new Set(metaSeq);
|
||||
}
|
||||
return [new MetaTuple(new RefValue(col), last.value, numLeaves, col), col];
|
||||
};
|
||||
@@ -231,11 +231,11 @@ export function newIndexedMetaSequenceChunkFn(kind: NomsKind, vr: ?ValueReader):
|
||||
let col: Collection;
|
||||
if (kind === Kind.List) {
|
||||
const metaSeq = newListMetaSequence(vr, tuples);
|
||||
col = new NomsList(metaSeq);
|
||||
col = new List(metaSeq);
|
||||
} else {
|
||||
invariant(kind === Kind.Blob);
|
||||
const metaSeq = newBlobMetaSequence(vr, tuples);
|
||||
col = new NomsBlob(metaSeq);
|
||||
col = new Blob(metaSeq);
|
||||
}
|
||||
return [new MetaTuple(new RefValue(col), sum, sum, col), col];
|
||||
};
|
||||
|
||||
+4
-4
@@ -4,7 +4,7 @@ export {AsyncIterator} from './async-iterator.js';
|
||||
export {default as BuzHash} from './buzhash.js';
|
||||
export {default as Database, newCommit} from './database.js';
|
||||
export {default as Dataset} from './dataset.js';
|
||||
export {newBlob, NomsBlob, BlobReader, BlobWriter} from './blob.js';
|
||||
export {default as Blob, newBlob, BlobReader, BlobWriter} from './blob.js';
|
||||
export {decodeNomsValue} from './decode.js';
|
||||
export {default as Chunk} from './chunk.js';
|
||||
export {default as HttpBatchStore} from './http-batch-store.js';
|
||||
@@ -21,9 +21,9 @@ export {
|
||||
export {encodeNomsValue} from './encode.js';
|
||||
export {invariant, notNull} from './assert.js';
|
||||
export {isPrimitiveKind, Kind, kindToString} from './noms-kind.js';
|
||||
export {newList, ListLeafSequence, NomsList} from './list.js';
|
||||
export {newMap, NomsMap, MapLeafSequence} from './map.js';
|
||||
export {newSet, NomsSet, SetLeafSequence} from './set.js';
|
||||
export {default as List, newList, ListLeafSequence} from './list.js';
|
||||
export {default as Map, newMap, MapLeafSequence} from './map.js';
|
||||
export {default as Set, newSet, SetLeafSequence} from './set.js';
|
||||
export {IndexedSequence} from './indexed-sequence.js';
|
||||
export {OrderedMetaSequence, IndexedMetaSequence} from './meta-sequence.js';
|
||||
export {SPLICE_AT, SPLICE_REMOVED, SPLICE_ADDED, SPLICE_FROM} from './edit-distance.js';
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
import tingodb from 'tingodb';
|
||||
import type {tcoll as Collection} from 'tingodb';
|
||||
import fs from 'fs';
|
||||
import {default as Chunk, emptyChunk} from './chunk.js';
|
||||
import Chunk, {emptyChunk} from './chunk.js';
|
||||
import {invariant} from './assert.js';
|
||||
|
||||
const __tingodb = tingodb();
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
import {assert} from 'chai';
|
||||
import {suite, test} from 'mocha';
|
||||
import {default as Ref, emptyRef} from './ref.js';
|
||||
import Ref, {emptyRef} from './ref.js';
|
||||
import {encode} from './utf8.js';
|
||||
|
||||
suite('Ref', () => {
|
||||
|
||||
+15
-15
@@ -13,7 +13,7 @@ import {newStruct} from './struct.js';
|
||||
import {flatten, flattenParallel, deriveCollectionHeight} from './test-util.js';
|
||||
import {invariant, notNull} from './assert.js';
|
||||
import {MetaTuple, newSetMetaSequence} from './meta-sequence.js';
|
||||
import {newSet, NomsSet, newSetLeafSequence} from './set.js';
|
||||
import Set, {newSet,newSetLeafSequence} from './set.js';
|
||||
import {OrderedSequence} from './ordered-sequence.js';
|
||||
import Ref from './ref.js';
|
||||
import type {ValueReadWriter} from './value-store.js';
|
||||
@@ -139,7 +139,7 @@ suite('BuildSet', () => {
|
||||
assert.deepEqual(nums, outNums);
|
||||
assert.strictEqual(testSetSize, s2.size);
|
||||
|
||||
invariant(s2 instanceof NomsSet);
|
||||
invariant(s2 instanceof Set);
|
||||
const s3 = await s2.remove(testSetSize - 1);
|
||||
const outNums2 = [];
|
||||
await s3.forEach(k => outNums2.push(k));
|
||||
@@ -194,7 +194,7 @@ suite('BuildSet', () => {
|
||||
assert.isTrue(equals(vals1[i], outVals[i]));
|
||||
}
|
||||
|
||||
invariant(s2 instanceof NomsSet);
|
||||
invariant(s2 instanceof Set);
|
||||
const s3 = await s2.remove(vals2[testSetSize - 1]); // removes struct
|
||||
const outVals2 = [];
|
||||
await s3.forEach(k => outVals2.push(k));
|
||||
@@ -209,7 +209,7 @@ suite('BuildSet', () => {
|
||||
suite('SetLeaf', () => {
|
||||
test('isEmpty/size', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const newSet = items => new NomsSet(newSetLeafSequence(ds, items));
|
||||
const newSet = items => new Set(newSetLeafSequence(ds, items));
|
||||
let s = newSet([]);
|
||||
assert.isTrue(s.isEmpty());
|
||||
assert.strictEqual(0, s.size);
|
||||
@@ -220,7 +220,7 @@ suite('SetLeaf', () => {
|
||||
|
||||
test('first/last/has', async () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const s = new NomsSet(newSetLeafSequence(ds, ['a', 'k']));
|
||||
const s = new Set(newSetLeafSequence(ds, ['a', 'k']));
|
||||
|
||||
assert.strictEqual('a', await s.first());
|
||||
assert.strictEqual('k', await s.last());
|
||||
@@ -233,7 +233,7 @@ suite('SetLeaf', () => {
|
||||
|
||||
test('forEach', async () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const m = new NomsSet(newSetLeafSequence(ds, ['a', 'b']));
|
||||
const m = new Set(newSetLeafSequence(ds, ['a', 'b']));
|
||||
|
||||
const values = [];
|
||||
await m.forEach((k) => { values.push(k); });
|
||||
@@ -244,7 +244,7 @@ suite('SetLeaf', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
|
||||
const test = async items => {
|
||||
const m = new NomsSet(newSetLeafSequence(ds, items));
|
||||
const m = new Set(newSetLeafSequence(ds, items));
|
||||
assert.deepEqual(items, await flatten(m.iterator()));
|
||||
assert.deepEqual(items, await flattenParallel(m.iterator(), items.length));
|
||||
};
|
||||
@@ -256,7 +256,7 @@ suite('SetLeaf', () => {
|
||||
|
||||
test('LONG: iteratorAt', async () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
const build = items => new NomsSet(newSetLeafSequence(ds, items));
|
||||
const build = items => new Set(newSetLeafSequence(ds, items));
|
||||
|
||||
assert.deepEqual([], await flatten(build([]).iteratorAt('a')));
|
||||
|
||||
@@ -276,7 +276,7 @@ suite('SetLeaf', () => {
|
||||
const r1 = ds.writeValue('x');
|
||||
const r2 = ds.writeValue('a');
|
||||
const r3 = ds.writeValue('b');
|
||||
const l = new NomsSet(newSetLeafSequence(ds, ['z', r1, r2, r3]));
|
||||
const l = new Set(newSetLeafSequence(ds, ['z', r1, r2, r3]));
|
||||
assert.strictEqual(3, l.chunks.length);
|
||||
assert.isTrue(equals(r1, l.chunks[0]));
|
||||
assert.isTrue(equals(r2, l.chunks[1]));
|
||||
@@ -285,21 +285,21 @@ suite('SetLeaf', () => {
|
||||
});
|
||||
|
||||
suite('CompoundSet', () => {
|
||||
function build(vwr: ValueReadWriter, values: Array<string>): NomsSet {
|
||||
function build(vwr: ValueReadWriter, values: Array<string>): Set {
|
||||
assert.isTrue(values.length > 1 && Math.log2(values.length) % 1 === 0);
|
||||
|
||||
let tuples = [];
|
||||
for (let i = 0; i < values.length; i += 2) {
|
||||
const l = new NomsSet(newSetLeafSequence(vwr, [values[i], values[i + 1]]));
|
||||
const l = new Set(newSetLeafSequence(vwr, [values[i], values[i + 1]]));
|
||||
const r = vwr.writeValue(l);
|
||||
tuples.push(new MetaTuple(r, values[i + 1], 2));
|
||||
}
|
||||
|
||||
let last: ?NomsSet = null;
|
||||
let last: ?Set = null;
|
||||
while (tuples.length > 1) {
|
||||
const next = [];
|
||||
for (let i = 0; i < tuples.length; i += 2) {
|
||||
last = new NomsSet(newSetMetaSequence(vwr, [tuples[i], tuples[i + 1]]));
|
||||
last = new Set(newSetMetaSequence(vwr, [tuples[i], tuples[i + 1]]));
|
||||
const r = vwr.writeValue(last);
|
||||
next.push(new MetaTuple(r, tuples[i + 1].value,
|
||||
tuples[i].numLeaves + tuples[i + 1].numLeaves));
|
||||
@@ -479,7 +479,7 @@ suite('CompoundSet', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
|
||||
const first = build(ds, seqs[0]);
|
||||
const sets:Array<NomsSet> = [];
|
||||
const sets:Array<Set> = [];
|
||||
for (let i = 1; i < seqs.length; i++) {
|
||||
sets.push(build(ds, seqs[i]));
|
||||
}
|
||||
@@ -508,7 +508,7 @@ suite('CompoundSet', () => {
|
||||
const ds = new Database(makeTestingBatchStore());
|
||||
|
||||
const test = async (expected, items) => {
|
||||
const set = new NomsSet(newSetLeafSequence(ds, items));
|
||||
const set = new Set(newSetLeafSequence(ds, items));
|
||||
const iter = set.iteratorAt(0);
|
||||
assert.deepEqual(expected, await flatten(iter));
|
||||
};
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ export function newSet<T:valueOrPrimitive>(values: Array<T>):
|
||||
newOrderedMetaSequenceBoundaryChecker);
|
||||
}
|
||||
|
||||
export class NomsSet<T: valueOrPrimitive> extends Collection<OrderedSequence> {
|
||||
export default class NomsSet<T: valueOrPrimitive> extends Collection<OrderedSequence> {
|
||||
async has(key: T): Promise<boolean> {
|
||||
const cursor = await this.sequence.newCursorAt(key);
|
||||
return cursor.valid && equals(cursor.getCurrentKey(), key);
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// @flow
|
||||
|
||||
import {makeTestingBatchStore} from './batch-store-adaptor.js';
|
||||
import {
|
||||
default as Struct,
|
||||
import Struct, {
|
||||
newStruct,
|
||||
newStructWithType,
|
||||
StructMirror,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @flow
|
||||
|
||||
import Chunk from './chunk.js';
|
||||
import {default as Ref, emptyRef} from './ref.js';
|
||||
import Ref, {emptyRef} from './ref.js';
|
||||
import RefValue from './ref-value.js';
|
||||
import type BatchStore from './batch-store.js';
|
||||
import type {valueOrPrimitive} from './value.js';
|
||||
|
||||
+7
-7
@@ -1,9 +1,9 @@
|
||||
// @flow
|
||||
|
||||
import {NomsBlob} from './blob.js';
|
||||
import {NomsList} from './list.js';
|
||||
import {NomsSet} from './set.js';
|
||||
import {NomsMap} from './map.js';
|
||||
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 Struct, {StructMirror} from './struct.js';
|
||||
|
||||
@@ -38,7 +38,7 @@ export default async function walk(v: valueOrPrimitive, ds: Database, cb: walkCb
|
||||
return;
|
||||
}
|
||||
|
||||
if (v instanceof NomsBlob) {
|
||||
if (v instanceof Blob) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -47,9 +47,9 @@ export default async function walk(v: valueOrPrimitive, ds: Database, cb: walkCb
|
||||
}
|
||||
|
||||
const p = [];
|
||||
if (v instanceof NomsList || v instanceof NomsSet) {
|
||||
if (v instanceof List || v instanceof Set) {
|
||||
await v.forEach(cv => void(p.push(walk(cv, ds, cb))));
|
||||
} else if (v instanceof NomsMap) {
|
||||
} else if (v instanceof Map) {
|
||||
await v.forEach((cv, k) => {
|
||||
p.push(walk(k, ds, cb));
|
||||
p.push(walk(cv, ds, cb));
|
||||
|
||||
+1
-3
@@ -3,7 +3,7 @@
|
||||
import {assert} from 'chai';
|
||||
import {suite, test} from 'mocha';
|
||||
import type {valueOrPrimitive} from './value.js';
|
||||
import {default as Database} from './database.js';
|
||||
import Database from './database.js';
|
||||
import {makeTestingBatchStore} from './batch-store-adaptor.js';
|
||||
|
||||
export class TestValue {
|
||||
@@ -57,5 +57,3 @@ suite('cross platform test', () => {
|
||||
await testSuite();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user