Merge pull request #1094 from arv/type-param-position

JS: Change the position of the type param to newList etc
This commit is contained in:
Erik Arvidsson
2016-03-17 14:20:43 -07:00
9 changed files with 35 additions and 35 deletions

View File

@@ -187,7 +187,7 @@ export default class DataManager {
const map = await this._datasetP;
const set = await map.get(r);
if (set === undefined) {
return newSet(setType, []);
return newSet([], setType);
}
invariant(set);

View File

@@ -149,7 +149,7 @@ suite('DataStore', () => {
const commit = await newCommit('foo', []);
const commitRef = writeValue(commit, commit.type, ms);
const datasets = await newMap(types.commitMapType, ['foo', commitRef]);
const datasets = await newMap(['foo', commitRef], types.commitMapType);
const rootRef = writeValue(datasets, datasets.type, ms);
assert.isTrue(await ms.updateRoot(rootRef, new Ref()));
ds = new DataStore(ms); // refresh the datasets

View File

@@ -27,7 +27,7 @@ type DatasTypes = {
let emptyCommitMap: Promise<NomsMap<string, Ref>>;
function getEmptyCommitMap(): Promise<NomsMap<string, Ref>> {
if (!emptyCommitMap) {
emptyCommitMap = newMap(getDatasTypes().commitMapType, []);
emptyCommitMap = newMap([], getDatasTypes().commitMapType);
}
return emptyCommitMap;
}
@@ -157,7 +157,7 @@ export class DataStore {
}
async function getAncestors(commits: NomsSet<Ref>, store: ChunkStore): Promise<NomsSet<Ref>> {
let ancestors = await newSet(getDatasTypes().commitSetType, []);
let ancestors = await newSet([], getDatasTypes().commitSetType);
await commits.map(async (commitRef) => {
const commit = await readValue(commitRef, store);
await commit.get('parents').map(async (ref) => ancestors = await ancestors.insert(ref));
@@ -168,6 +168,6 @@ async function getAncestors(commits: NomsSet<Ref>, store: ChunkStore): Promise<N
export function newCommit(value: valueOrPrimitive, parents: Array<Ref> = []):
Promise<Struct> {
const types = getDatasTypes();
return newSet(types.commitSetType, parents).then(parents =>
return newSet(parents, types.commitSetType).then(parents =>
new Struct(types.commitType, types.commitTypeDef, {value,parents}));
}

View File

@@ -43,7 +43,7 @@ suite('BuildList', () => {
test('set of n numbers, length', async () => {
const nums = firstNNumbers(testListSize);
const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64));
const s = await newList(tr, nums);
const s = await newList(nums, tr);
assert.strictEqual(s.ref.toString(), listOfNRef);
assert.strictEqual(testListSize, s.length);
});
@@ -51,7 +51,7 @@ suite('BuildList', () => {
test('toJS', async () => {
const nums = firstNNumbers(5000);
const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64));
const s = await newList(tr, nums);
const s = await newList(nums, tr);
assert.strictEqual(s.ref.toString(), listOfNRef);
assert.strictEqual(testListSize, s.length);
@@ -71,7 +71,7 @@ suite('BuildList', () => {
test('insert', async () => {
const nums = firstNNumbers(testListSize - 10);
const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64));
let s = await newList(tr, nums);
let s = await newList(nums, tr);
for (let i = testListSize - 10; i < testListSize; i++) {
s = await s.insert(i, [i]);
@@ -83,7 +83,7 @@ suite('BuildList', () => {
test('append', async () => {
const nums = firstNNumbers(testListSize - 10);
const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64));
let s = await newList(tr, nums);
let s = await newList(nums, tr);
for (let i = testListSize - 10; i < testListSize; i++) {
s = await s.append([i]);
@@ -95,7 +95,7 @@ suite('BuildList', () => {
test('remove', async () => {
const nums = firstNNumbers(testListSize + 10);
const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64));
let s = await newList(tr, nums);
let s = await newList(nums, tr);
let count = 10;
while (count-- > 0) {
@@ -108,7 +108,7 @@ suite('BuildList', () => {
test('splice', async () => {
const nums = firstNNumbers(testListSize);
const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64));
let s = await newList(tr, nums);
let s = await newList(nums, tr);
const splice500At = async (idx: number) => {
s = await s.splice(idx, [], 500);
@@ -128,7 +128,7 @@ suite('BuildList', () => {
const nums = firstNNumbers(testListSize);
const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64));
const s = await newList(tr, nums);
const s = await newList(nums, tr);
const r = writeValue(s, tr, ms);
const s2 = await readValue(r, ms);
const outNums = await s2.toJS();
@@ -349,8 +349,8 @@ suite('Diff List', () => {
const directDiff = calcSplices(nums1.length, nums2.length, (i, j) => nums1[i] === nums2[j]);
const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64));
const l1 = await newList(tr, nums1);
const l2 = await newList(tr, nums2);
const l1 = await newList(nums1, tr);
const l2 = await newList(nums2, tr);
const listDiff = await l2.diff(l1);
assert.deepEqual(directDiff, listDiff);
@@ -368,8 +368,8 @@ suite('Diff List', () => {
const directDiff = calcSplices(nums1.length, nums2.length, (i, j) => nums1[i] === nums2[j]);
const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64));
const l1 = await newList(tr, nums1);
const l2 = await newList(tr, nums2);
const l1 = await newList(nums1, tr);
const l2 = await newList(nums2, tr);
const listDiff = await l2.diff(l1);
assert.deepEqual(directDiff, listDiff);
@@ -387,8 +387,8 @@ suite('Diff List', () => {
const directDiff = calcSplices(nums1.length, nums2.length, (i, j) => nums1[i] === nums2[j]);
const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64));
const l1 = await newList(tr, nums1);
const l2 = await newList(tr, nums2);
const l1 = await newList(nums1, tr);
const l2 = await newList(nums2, tr);
const listDiff = await l2.diff(l1);
assert.deepEqual(directDiff, listDiff);
@@ -400,8 +400,8 @@ suite('Diff List', () => {
const directDiff = calcSplices(nums1.length, nums2.length, (i, j) => nums1[i] === nums2[j]);
const tr = makeCompoundType(Kind.List, makePrimitiveType(Kind.Int64));
const l1 = await newList(tr, nums1);
const l2 = await newList(tr, nums2);
const l1 = await newList(nums1, tr);
const l2 = await newList(nums2, tr);
const listDiff = await l2.diff(l1);
assert.deepEqual(directDiff, listDiff);

View File

@@ -33,7 +33,7 @@ function newListLeafBoundaryChecker<T: valueOrPrimitive>(t: Type): BoundaryCheck
);
}
export function newList<T: valueOrPrimitive>(type: Type, values: Array<T>):
export function newList<T: valueOrPrimitive>(values: Array<T>, type: Type):
Promise<NomsList<T>> {
return chunkSequence(null, values, 0, newListLeafChunkFn(type),
newIndexedMetaSequenceChunkFn(type),

View File

@@ -28,7 +28,7 @@ suite('BuildMap', () => {
const tr = makeCompoundType(Kind.Map, makePrimitiveType(Kind.Int64),
makePrimitiveType(Kind.Int64));
const m = await newMap(tr, kvs);
const m = await newMap(kvs, tr);
assert.strictEqual(m.ref.toString(), mapOfNRef);
// shuffle kvs, and test that the constructor sorts properly
@@ -39,7 +39,7 @@ suite('BuildMap', () => {
pairs.sort(() => Math.random() > .5 ? 1 : -1);
kvs.length = 0;
pairs.forEach(kv => kvs.push(kv.k, kv.v));
const m2 = await newMap(tr, kvs);
const m2 = await newMap(kvs, tr);
assert.strictEqual(m2.ref.toString(), mapOfNRef);
});
@@ -51,7 +51,7 @@ suite('BuildMap', () => {
const tr = makeCompoundType(Kind.Map, makePrimitiveType(Kind.Int64),
makePrimitiveType(Kind.Int64));
let m = await newMap(tr, kvs);
let m = await newMap(kvs, tr);
for (let i = testMapSize - 10; i < testMapSize; i++) {
m = await m.set(i, i + 1);
}
@@ -67,7 +67,7 @@ suite('BuildMap', () => {
const tr = makeCompoundType(Kind.Map, makePrimitiveType(Kind.Int64),
makePrimitiveType(Kind.Int64));
let m = await newMap(tr, kvs);
let m = await newMap(kvs, tr);
for (let i = 0; i < testMapSize; i++) {
m = await m.set(i, i + 1);
}
@@ -83,7 +83,7 @@ suite('BuildMap', () => {
const tr = makeCompoundType(Kind.Map, makePrimitiveType(Kind.Int64),
makePrimitiveType(Kind.Int64));
let m = await newMap(tr, kvs);
let m = await newMap(kvs, tr);
for (let i = testMapSize; i < testMapSize + 10; i++) {
m = await m.remove(i);
}
@@ -101,7 +101,7 @@ suite('BuildMap', () => {
const tr = makeCompoundType(Kind.Map, makePrimitiveType(Kind.Int64),
makePrimitiveType(Kind.Int64));
const m = await newMap(tr, kvs);
const m = await newMap(kvs, tr);
const r = writeValue(m, tr, ms);
const m2 = await readValue(r, ms);

View File

@@ -64,8 +64,8 @@ function buildMapData(t: Type, kvs: Array<any>): Array<MapEntry> {
return entries;
}
export function newMap<K: valueOrPrimitive, V: valueOrPrimitive>(type: Type,
kvs: Array<any>): Promise<NomsMap<K, V>> {
export function newMap<K: valueOrPrimitive, V: valueOrPrimitive>(kvs: Array<any>, type: Type):
Promise<NomsMap<K, V>> {
return chunkSequence(null, buildMapData(type, kvs), 0, newMapLeafChunkFn(type),
newOrderedMetaSequenceChunkFn(type),
newMapLeafBoundaryChecker(type),

View File

@@ -33,19 +33,19 @@ suite('BuildSet', () => {
test('set of n numbers', async () => {
const nums = firstNNumbers(testSetSize);
const tr = makeCompoundType(Kind.Set, makePrimitiveType(Kind.Int64));
const s = await newSet(tr, nums);
const s = await newSet(nums, tr);
assert.strictEqual(s.ref.toString(), setOfNRef);
// shuffle kvs, and test that the constructor sorts properly
nums.sort(() => Math.random() > .5 ? 1 : -1);
const s2 = await newSet(tr, nums);
const s2 = await newSet(nums, tr);
assert.strictEqual(s2.ref.toString(), setOfNRef);
});
test('insert', async () => {
const nums = firstNNumbers(testSetSize - 10);
const tr = makeCompoundType(Kind.Set, makePrimitiveType(Kind.Int64));
let s = await newSet(tr, nums);
let s = await newSet(nums, tr);
for (let i = testSetSize - 10; i < testSetSize; i++) {
s = await s.insert(i);
@@ -57,7 +57,7 @@ suite('BuildSet', () => {
test('remove', async () => {
const nums = firstNNumbers(testSetSize + 10);
const tr = makeCompoundType(Kind.Set, makePrimitiveType(Kind.Int64));
let s = await newSet(tr, nums);
let s = await newSet(nums, tr);
let count = 10;
while (count-- > 0) {
@@ -72,7 +72,7 @@ suite('BuildSet', () => {
const nums = firstNNumbers(testSetSize);
const tr = makeCompoundType(Kind.Set, makePrimitiveType(Kind.Int64));
const s = await newSet(tr, nums);
const s = await newSet(nums, tr);
const r = writeValue(s, tr, ms);
const s2 = await readValue(r, ms);
const outNums = [];

View File

@@ -53,7 +53,7 @@ function buildSetData<T>(t: Type, values: Array<any>): Array<T> {
return values;
}
export function newSet<T:valueOrPrimitive>(type: Type, values: Array<T>):
export function newSet<T:valueOrPrimitive>(values: Array<T>, type: Type):
Promise<NomsSet<T>> {
return chunkSequence(null, buildSetData(type, values), 0, newSetLeafChunkFn(type),