@isopodlabs/utilities 1.7.0 → 1.7.1

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/dist/bits.d.ts CHANGED
@@ -126,13 +126,14 @@ export declare class DenseBits32 implements BitSet {
126
126
  selfDifference(other: DenseBits32): this;
127
127
  clean(): this;
128
128
  }
129
- type SparseNumberArray = number[] | Record<number, number>;
129
+ type sparsebits = Record<number, number>;
130
+ type SparseNumberArray = number[] | sparsebits;
130
131
  type ExtraParams<T> = T extends new (bits: SparseNumberArray, ...args: infer P) => any ? P : never;
131
132
  export declare class SparseBits implements BitSet {
132
- protected bits: number[];
133
+ protected bits: sparsebits;
133
134
  constructor(bits?: SparseNumberArray);
134
135
  protected create(bits?: SparseNumberArray): this;
135
- static fromEntries<C extends new (bits: SparseNumberArray, ...args: any[]) => any>(this: C, entries: Record<number, number> | [number, number][], ...extra: ExtraParams<C>): InstanceType<C>;
136
+ static fromEntries<C extends new (bits: SparseNumberArray, ...args: any[]) => any>(this: C, entries: sparsebits | [number, number][], ...extra: ExtraParams<C>): InstanceType<C>;
136
137
  static fromIndices<C extends new (bits: SparseNumberArray, ...args: any[]) => any>(this: C, ...indices: number[]): InstanceType<C>;
137
138
  static fromIndices<C extends new (bits: SparseNumberArray, ...args: any[]) => any>(this: C, indices: number[], ...extra: ExtraParams<C>): InstanceType<C>;
138
139
  copy(): this;
package/dist/bits.js CHANGED
@@ -702,11 +702,8 @@ class DenseBits32 {
702
702
  }
703
703
  exports.DenseBits32 = DenseBits32;
704
704
  ;
705
- //-----------------------------------------------------------------------------
706
- // SparseBits - a sparse bitset where each entry in the 'bits' array represents 32 bits
707
- //-----------------------------------------------------------------------------
708
705
  function sparseFromIndices(indices) {
709
- const bits = [];
706
+ const bits = {};
710
707
  for (const i of indices)
711
708
  bits[i >> 5] |= 1 << (i & 0x1f);
712
709
  return bits;
@@ -816,7 +813,10 @@ function sparseNthSet(bits, a, undef = 0) {
816
813
  return -1;
817
814
  }
818
815
  function sparseComplement(bits) {
819
- return bits.map(b => ~b);
816
+ const result = [];
817
+ for (const i in bits)
818
+ result[i] = ~bits[i];
819
+ return result;
820
820
  }
821
821
  function sparseIntersect(bits, other) {
822
822
  const result = [];
@@ -1013,13 +1013,15 @@ function sparseSlice(bits, from, to) {
1013
1013
  for (const k in bits) {
1014
1014
  const i = +k;
1015
1015
  if (i >= from32) {
1016
- if (i > to32)
1017
- break;
1018
1016
  let b = bits[k];
1019
1017
  if (i === from32)
1020
1018
  b &= -fromM;
1021
- if (i === to32)
1019
+ if (i === to32) {
1022
1020
  b &= toM - 1;
1021
+ if (b !== 0)
1022
+ result[k] = b;
1023
+ break;
1024
+ }
1023
1025
  if (b !== 0)
1024
1026
  result[k] = b;
1025
1027
  }
@@ -1029,7 +1031,7 @@ function sparseSlice(bits, from, to) {
1029
1031
  class SparseBits {
1030
1032
  bits;
1031
1033
  constructor(bits = []) {
1032
- this.bits = bits;
1034
+ this.bits = bits; // as Record<number, number>;
1033
1035
  }
1034
1036
  create(bits = []) {
1035
1037
  return new this.constructor(bits);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@isopodlabs/utilities",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "Various typescript helpers.",
5
5
  "repository": {
6
6
  "type": "git",