@peerbit/shared-log 10.1.0 → 10.2.0-f461b9a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/ranges.ts CHANGED
@@ -1807,18 +1807,21 @@ export const getAllMergeCandiates = async <R extends "u32" | "u64">(
1807
1807
  id: Uint8Array;
1808
1808
  },
1809
1809
  numbers: Numbers<R>,
1810
- ): Promise<ReplicationRangeIndexable<R>[]> => {
1810
+ ): Promise<MapIterator<ReplicationRangeIndexable<R>>> => {
1811
1811
  const adjacent = await getAdjecentSameOwner(peers, range, numbers);
1812
1812
  const covering = await getCoveringRangesSameOwner(peers, range).all();
1813
1813
 
1814
- let ret: ReplicationRangeIndexable<R>[] = [];
1814
+ let ret: Map<string, ReplicationRangeIndexable<R>> = new Map();
1815
1815
  if (adjacent.below) {
1816
- ret.push(adjacent.below);
1816
+ ret.set(adjacent.below.idString, adjacent.below);
1817
1817
  }
1818
1818
  if (adjacent.above) {
1819
- ret.push(adjacent.above);
1819
+ ret.set(adjacent.above.idString, adjacent.above);
1820
1820
  }
1821
- return [...ret, ...covering.map((x) => x.value)];
1821
+ for (const range of covering) {
1822
+ ret.set(range.value.idString, range.value);
1823
+ }
1824
+ return ret.values();
1822
1825
  };
1823
1826
 
1824
1827
  export const isMatured = (
@@ -1828,72 +1831,6 @@ export const isMatured = (
1828
1831
  ) => {
1829
1832
  return now - Number(segment.timestamp) >= minAge;
1830
1833
  };
1831
- /*
1832
-
1833
- const collectNodesAroundPoint = async <R extends "u32" | "u64">(
1834
- roleAge: number,
1835
- peers: Index<ReplicationRangeIndexable<R>>,
1836
- collector: (
1837
- rect: { hash: string },
1838
- matured: boolean,
1839
- intersecting: boolean,
1840
- ) => void,
1841
- point: NumberFromType<R>,
1842
- now: number,
1843
- numbers: Numbers<R>,
1844
- done: () => boolean = () => true,
1845
- ) => {
1846
- const containing = iterateRangesContainingPoint<
1847
- { timestamp: true, hash: true },
1848
- R
1849
- >(peers, point, 0, true, now, { shape: { timestamp: true, hash: true } as const });
1850
- const allContaining = await containing.all();
1851
- for (const rect of allContaining) {
1852
- collector(rect.value, isMatured(rect.value, now, roleAge), true);
1853
- }
1854
-
1855
- if (done()) {
1856
- return;
1857
- }
1858
-
1859
- const closestBelow = getClosest<undefined, R>(
1860
- "below",
1861
- peers,
1862
- point,
1863
- 0,
1864
- true,
1865
- now,
1866
- false,
1867
- numbers
1868
- );
1869
- const closestAbove = getClosest<undefined, R>(
1870
- "above",
1871
- peers,
1872
- point,
1873
- 0,
1874
- true,
1875
- now,
1876
- false,
1877
- numbers
1878
- );
1879
- const aroundIterator = joinIterator<undefined, R>(
1880
- [closestBelow, closestAbove],
1881
- point,
1882
- "closest",
1883
- numbers,
1884
- );
1885
- while (aroundIterator.done() !== true && done() !== true) {
1886
- const res = await aroundIterator.next(1);
1887
- for (const rect of res) {
1888
- collector(rect.value, isMatured(rect.value, now, roleAge), false);
1889
- if (done()) {
1890
- return;
1891
- }
1892
- }
1893
- }
1894
- };
1895
- */
1896
-
1897
1834
  const collectClosestAround = async <R extends "u32" | "u64">(
1898
1835
  roleAge: number,
1899
1836
  peers: Index<ReplicationRangeIndexable<R>>,
@@ -1909,13 +1846,6 @@ const collectClosestAround = async <R extends "u32" | "u64">(
1909
1846
  point,
1910
1847
  false,
1911
1848
  numbers,
1912
- /* {
1913
- time: {
1914
- matured: true,
1915
- roleAgeLimit: 0,
1916
- now
1917
- }
1918
- } */
1919
1849
  );
1920
1850
  const closestAbove = getClosest<undefined, R>(
1921
1851
  "above",
@@ -1923,13 +1853,6 @@ const collectClosestAround = async <R extends "u32" | "u64">(
1923
1853
  point,
1924
1854
  false,
1925
1855
  numbers,
1926
- /* {
1927
- time: {
1928
- matured: true,
1929
- roleAgeLimit: 0,
1930
- now
1931
- }
1932
- } */
1933
1856
  );
1934
1857
 
1935
1858
  const aroundIterator = joinIterator<undefined, R>(
@@ -2283,21 +2206,6 @@ export const getCoverSet = async <R extends "u32" | "u64">(properties: {
2283
2206
  start instanceof PublicSignKey && ret.add(start.hashcode());
2284
2207
  return ret;
2285
2208
  };
2286
- /* export const getReplicationDiff = (changes: ReplicationChange) => {
2287
- // reduce the change set to only regions that are changed for each peer
2288
- // i.e. subtract removed regions from added regions, and vice versa
2289
- const result = new Map<string, { range: ReplicationRangeIndexable, added: boolean }[]>();
2290
-
2291
- for (const addedChange of changes.added ?? []) {
2292
- let prev = result.get(addedChange.hash) ?? [];
2293
- for (const [_hash, ranges] of result.entries()) {
2294
- for (const r of ranges) {
2295
-
2296
- }
2297
- }
2298
- }
2299
- }
2300
- */
2301
2209
 
2302
2210
  export const matchEntriesInRangeQuery = (range: {
2303
2211
  start1: number | bigint;