Skip to content

Commit

Permalink
[mergeable] Remove getHash methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgpearce committed Mar 19, 2024
1 parent 2e86b37 commit 67dd202
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 212 deletions.
47 changes: 9 additions & 38 deletions src/mergeable-store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import {CellOrUndefined, Changes, Store, ValueOrUndefined} from './types/store';
import {EMPTY_STRING, strEndsWith, strStartsWith} from './common/strings';
import {
Hash,
IdObj,
objEnsure,
objForEach,
objFreeze,
objIsEmpty,
objNew,
objToArray,
} from './common/obj';
import {
MergeableChanges,
MergeableContent,
MergeableStore,
Expand All @@ -13,15 +21,6 @@ import {
ValuesStamp,
createMergeableStore as createMergeableStoreDecl,
} from './types/mergeable-store';
import {
IdObj,
objEnsure,
objForEach,
objFreeze,
objIsEmpty,
objNew,
objToArray,
} from './common/obj';
import {
RowStampMap,
StampMap,
Expand Down Expand Up @@ -409,27 +408,6 @@ export const createMergeableStore = ((id: Id): MergeableStore => {
return applyMergeableChanges(mergeableChanges2);
};

const getContentHash = (): Hash => contentStampMap[2];

const getTablesHash = (): Hash => contentStampMap[1][0][2];

const getTableHash = (tableId: Id): Hash =>
mapGet(contentStampMap[1][0][1], tableId)?.[2] ?? 0;

const getRowHash = (tableId: Id, rowId: Id): Hash =>
mapGet(mapGet(contentStampMap[1][0][1], tableId)?.[1], rowId)?.[2] ?? 0;

const getCellHash = (tableId: Id, rowId: Id, cellId: Id): Hash =>
mapGet(
mapGet(mapGet(contentStampMap[1][0][1], tableId)?.[1], rowId)?.[1],
cellId,
)?.[2] ?? 0;

const getValuesHash = (): Hash => contentStampMap[1][1][2];

const getValueHash = (valueId: Id): Hash =>
mapGet(contentStampMap[1][1][1], valueId)?.[2] ?? 0;

const mergeableStore: IdObj<any> = {
getMergeableContent,
getMergeableContentDelta,
Expand All @@ -441,13 +419,6 @@ export const createMergeableStore = ((id: Id): MergeableStore => {
getTransactionMergeableChanges,
applyMergeableChanges,
merge,
getContentHash,
getTablesHash,
getTableHash,
getRowHash,
getCellHash,
getValuesHash,
getValueHash,
};

(store as any).setInternalListeners(
Expand Down
41 changes: 3 additions & 38 deletions src/types/docs/mergeable-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@
*/
/// MergeableStore
{
/**
* The merge method
* @category Merging
*/
/// MergeableStore.merge
/**
* The getMergeableContent method
* @category Merging
Expand Down Expand Up @@ -116,40 +111,10 @@
*/
/// MergeableStore.applyMergeableChanges
/**
* The getContentHash method
* @category Hashes
*/
/// MergeableStore.getContentHash
/**
* The getTablesHash method
* @category Hashes
*/
/// MergeableStore.getTablesHash
/**
* The getTableHash method
* @category Hashes
*/
/// MergeableStore.getTableHash
/**
* The getRowHash method
* @category Hashes
*/
/// MergeableStore.getRowHash
/**
* The getCellHash method
* @category Hashes
*/
/// MergeableStore.getCellHash
/**
* The getValuesHash method
* @category Hashes
*/
/// MergeableStore.getValuesHash
/**
* The getValueHash method
* @category Hashes
* The merge method
* @category Merging
*/
/// MergeableStore.getValueHash
/// MergeableStore.merge
}
/**
* The createMergeableStore function
Expand Down
25 changes: 2 additions & 23 deletions src/types/mergeable-store.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ export type MergeableChanges = Stamp<
/// MergeableStore
export interface MergeableStore extends Store {
//
/// MergeableStore.merge
merge(mergeableStore: MergeableStore): MergeableStore;

/// MergeableStore.getMergeableContent
getMergeableContent(): MergeableContent;

Expand Down Expand Up @@ -100,26 +97,8 @@ export interface MergeableStore extends Store {
mergeableChanges: MergeableChanges | MergeableContent,
): MergeableStore;

/// MergeableStore.getContentHash
getContentHash(): Hash;

/// MergeableStore.getTablesHash
getTablesHash(): Hash;

/// MergeableStore.getTableHash
getTableHash(tableId: Id): Hash;

/// MergeableStore.getRowHash
getRowHash(tableId: Id, rowId: Id): Hash;

/// MergeableStore.getCellHash
getCellHash(tableId: Id, rowId: Id, cellId: Id): Hash;

/// MergeableStore.getValuesHash
getValuesHash(): Hash;

/// MergeableStore.getValueHash
getValueHash(valueId: Id): Hash;
/// MergeableStore.merge
merge(mergeableStore: MergeableStore): MergeableStore;
}

/// createMergeableStore
Expand Down
32 changes: 2 additions & 30 deletions src/types/with-schemas/mergeable-store.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,6 @@ export type MergeableChanges<Schemas extends OptionalSchemas> = Stamp<
export interface MergeableStore<Schemas extends OptionalSchemas>
extends Store<Schemas> {
//
/// MergeableStore.merge
merge(mergeableStore: MergeableStore<Schemas>): MergeableStore<Schemas>;

/// MergeableStore.getMergeableContent
getMergeableContent(): MergeableContent<Schemas>;

Expand Down Expand Up @@ -168,33 +165,8 @@ export interface MergeableStore<Schemas extends OptionalSchemas>
mergeableChanges: MergeableChanges<Schemas> | MergeableContent<Schemas>,
): MergeableStore<Schemas>;

/// MergeableStore.getContentHash
getContentHash(): Hash;

/// MergeableStore.getTablesHash
getTablesHash(): Hash;

/// MergeableStore.getTableHash
getTableHash(tableId: TableIdFromSchema<Schemas[0]>): Hash;

/// MergeableStore.getRowHash
getRowHash<TableId extends TableIdFromSchema<Schemas[0]>>(
tableId: TableId,
rowId: Id,
): Hash;

/// MergeableStore.getCellHash
getCellHash<TableId extends TableIdFromSchema<Schemas[0]>>(
tableId: TableId,
rowId: Id,
cellId: CellIdFromSchema<Schemas[0], TableId>,
): Hash;

/// MergeableStore.getValuesHash
getValuesHash(): Hash;

/// MergeableStore.getValueHash
getValueHash(valueId: ValueIdFromSchema<Schemas[1]>): Hash;
/// MergeableStore.merge
merge(mergeableStore: MergeableStore<Schemas>): MergeableStore<Schemas>;

/// Store.setTablesSchema
setTablesSchema<TS extends TablesSchema>(
Expand Down
83 changes: 0 additions & 83 deletions test/unit/other/mergeable-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -928,86 +928,3 @@ describe('Merge', () => {
});
});
});

describe('Hashing', () => {
let store: MergeableStore;
beforeEach(() => {
store = createMergeableStore('s1');
store.setContent([
{t1: {r1: {c1: 1, c2: 2}, r2: {c1: 3}}, t2: {r1: {c1: 4}}},
{v1: 5, v2: 6},
]);
});

test('getContentHash', () => {
expect(store.getContentHash()).toEqual(264108303);
store.setCell('t1', 'r1', 'c1', 2);
expect(store.getContentHash()).toEqual(2310866048);
store.setValue('v1', 6);
expect(store.getContentHash()).toEqual(1294518153);
});

test('getTablesHash', () => {
expect(store.getTablesHash()).toEqual(3461913939);
store.setCell('t1', 'r1', 'c1', 2);
expect(store.getTablesHash()).toEqual(1213751516);
store.setCell('t1', 'r1', 'c2', 3);
expect(store.getTablesHash()).toEqual(3363883081);
});

test('getTableHash', () => {
expect(store.getTableHash('t0')).toEqual(0);
expect(store.getTableHash('t1')).toEqual(3256293025);
expect(store.getTableHash('t2')).toEqual(2257770474);
store.setCell('t1', 'r1', 'c1', 2);
expect(store.getTableHash('t1')).toEqual(1976901808);
store.setCell('t1', 'r1', 'c2', 3);
expect(store.getTableHash('t1')).toEqual(3838433038);
});

test('getRowHash', () => {
expect(store.getRowHash('t0', 'r0')).toEqual(0);
expect(store.getRowHash('t1', 'r0')).toEqual(0);
expect(store.getRowHash('t1', 'r1')).toEqual(922886432);
store.setCell('t1', 'r1', 'c1', 2);
expect(store.getRowHash('t1', 'r1')).toEqual(1796263321);
store.setCell('t1', 'r1', 'c2', 3);
expect(store.getRowHash('t1', 'r1')).toEqual(4234418496);
});

test('getCellHash', () => {
expect(store.getCellHash('t0', 'r1', 'c1')).toEqual(0);
expect(store.getCellHash('t1', 'r0', 'c1')).toEqual(0);
expect(store.getCellHash('t1', 'r1', 'c0')).toEqual(0);
expect(store.getCellHash('t1', 'r1', 'c1')).toEqual(4065945599);
expect(store.getCellHash('t1', 'r1', 'c2')).toEqual(903550280);
expect(store.getCellHash('t1', 'r2', 'c1')).toEqual(2609181593);
expect(store.getCellHash('t2', 'r1', 'c1')).toEqual(4060269138);
store.setCell('t1', 'r1', 'c1', 2);
expect(store.getCellHash('t1', 'r1', 'c1')).toEqual(2669080357);
expect(store.getCellHash('t1', 'r1', 'c2')).toEqual(903550280);
store.setCell('t1', 'r1', 'c2', 3);
expect(store.getCellHash('t1', 'r1', 'c1')).toEqual(2669080357);
expect(store.getCellHash('t1', 'r1', 'c2')).toEqual(3252714811);
});

test('getValuesHash', () => {
expect(store.getValuesHash()).toEqual(3253036124);
store.setValue('v1', 6);
expect(store.getValuesHash()).toEqual(329578120);
store.setValue('v2', 7);
expect(store.getValuesHash()).toEqual(1695179121);
});

test('getValueHash', () => {
expect(store.getValueHash('v0')).toEqual(0);
expect(store.getValueHash('v1')).toEqual(2123438739);
expect(store.getValueHash('v2')).toEqual(4199459148);
store.setValue('v1', 6);
expect(store.getValueHash('v1')).toEqual(1736877145);
expect(store.getValueHash('v2')).toEqual(4199459148);
store.setValue('v2', 7);
expect(store.getValueHash('v1')).toEqual(1736877145);
expect(store.getValueHash('v2')).toEqual(3628841839);
});
});

0 comments on commit 67dd202

Please sign in to comment.