@tstdl/base 0.83.8 → 0.83.9

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.
@@ -2,8 +2,7 @@ import { Dictionary } from './dictionary.js';
2
2
  type Node = {
3
3
  nodeKey: any;
4
4
  parentNode: Node | undefined;
5
- hasInnerMap: boolean;
6
- children: Map<any, Node>;
5
+ children: Map<any, Node> | undefined;
7
6
  hasValue: boolean;
8
7
  value: any;
9
8
  };
@@ -21,7 +21,6 @@ __export(multi_key_map_exports, {
21
21
  MultiKeyMap: () => MultiKeyMap
22
22
  });
23
23
  module.exports = __toCommonJS(multi_key_map_exports);
24
- var import_lazy_property = require("../utils/object/lazy-property.js");
25
24
  var import_type_guards = require("../utils/type-guards.js");
26
25
  var import_circular_buffer = require("./circular-buffer.js");
27
26
  var import_dictionary = require("./dictionary.js");
@@ -32,7 +31,7 @@ class MultiKeyMap extends import_dictionary.Dictionary {
32
31
  constructor(newMapProvider = () => /* @__PURE__ */ new Map()) {
33
32
  super();
34
33
  this.newMapProvider = newMapProvider;
35
- this.rootNode = createNode(void 0, void 0, this.newMapProvider);
34
+ this.rootNode = createNode(void 0, void 0);
36
35
  }
37
36
  includes([key, value]) {
38
37
  if (!this.has(key)) {
@@ -54,10 +53,9 @@ class MultiKeyMap extends import_dictionary.Dictionary {
54
53
  }
55
54
  set(key, value) {
56
55
  const node = this.getNode(key, true);
57
- const hasValue = node.hasValue;
58
- node.hasValue = true;
59
56
  node.value = value;
60
- if (!hasValue) {
57
+ if (!node.hasValue) {
58
+ node.hasValue = true;
61
59
  this.incrementSize();
62
60
  }
63
61
  }
@@ -65,14 +63,14 @@ class MultiKeyMap extends import_dictionary.Dictionary {
65
63
  return this.has(key);
66
64
  }
67
65
  has(key) {
68
- const node = this.getNode(key, false);
66
+ const node = this.getNode(key);
69
67
  return (0, import_type_guards.isDefined)(node) && node.hasValue;
70
68
  }
71
69
  getFlat(...key) {
72
70
  return this.get(key);
73
71
  }
74
72
  get(key) {
75
- const node = this.getNode(key, false);
73
+ const node = this.getNode(key);
76
74
  if ((0, import_type_guards.isUndefined)(node)) {
77
75
  return void 0;
78
76
  }
@@ -82,7 +80,7 @@ class MultiKeyMap extends import_dictionary.Dictionary {
82
80
  return this.delete(key);
83
81
  }
84
82
  delete(key) {
85
- const node = this.getNode(key, false);
83
+ const node = this.getNode(key);
86
84
  if ((0, import_type_guards.isUndefined)(node)) {
87
85
  return false;
88
86
  }
@@ -118,7 +116,7 @@ class MultiKeyMap extends import_dictionary.Dictionary {
118
116
  if (node.hasValue) {
119
117
  yield [key, node.value];
120
118
  }
121
- if (node.hasInnerMap) {
119
+ if ((0, import_type_guards.isDefined)(node.children)) {
122
120
  for (const innerNode of node.children.values()) {
123
121
  queue.add([[...key, innerNode.nodeKey], innerNode]);
124
122
  }
@@ -126,48 +124,44 @@ class MultiKeyMap extends import_dictionary.Dictionary {
126
124
  }
127
125
  }
128
126
  _clear() {
129
- this.rootNode = createNode(void 0, void 0, this.newMapProvider);
130
- }
131
- getNode(key, create) {
132
- let node = getOrCreateChildNode(this.rootNode, key[0], this.newMapProvider);
133
- for (let i = 1; i < key.length; i++) {
134
- if (!node.hasInnerMap && !create) {
135
- return void 0;
127
+ this.rootNode = createNode(void 0, void 0);
128
+ this.setSize(0);
129
+ }
130
+ getNode(key, create = false) {
131
+ let node = this.rootNode;
132
+ for (const nodeKey of key) {
133
+ if ((0, import_type_guards.isUndefined)(node.children)) {
134
+ if (!create) {
135
+ return void 0;
136
+ }
137
+ node.children = this.newMapProvider();
138
+ }
139
+ let childNode = node.children.get(nodeKey);
140
+ if ((0, import_type_guards.isUndefined)(childNode)) {
141
+ if (!create) {
142
+ return void 0;
143
+ }
144
+ childNode = createNode(nodeKey, node);
145
+ node.children.set(nodeKey, childNode);
136
146
  }
137
- node = getOrCreateChildNode(this.rootNode, key[i], this.newMapProvider);
147
+ node = childNode;
138
148
  }
139
149
  return node;
140
150
  }
141
151
  deleteNodeIfEmpty(node) {
142
- if (node.hasValue || node.hasInnerMap && node.children.size > 0 || (0, import_type_guards.isUndefined)(node.parentNode)) {
152
+ if (node.hasValue || (0, import_type_guards.isDefined)(node.children) && node.children.size > 0 || (0, import_type_guards.isUndefined)(node.parentNode)) {
143
153
  return;
144
154
  }
145
155
  node.parentNode.children.delete(node.nodeKey);
146
156
  this.deleteNodeIfEmpty(node.parentNode);
147
157
  }
148
158
  }
149
- function getOrCreateChildNode(node, key, newMapProvider) {
150
- const childNode = node.children.get(key);
151
- if ((0, import_type_guards.isDefined)(childNode)) {
152
- return childNode;
153
- }
154
- const newNode = createNode(key, node, newMapProvider);
155
- node.children.set(key, newNode);
156
- return newNode;
157
- }
158
- function createNode(nodeKey, parentNode, newMapProvider) {
159
- return (0, import_lazy_property.lazyObject)({
160
- nodeKey: { value: nodeKey },
161
- parentNode: { value: parentNode },
162
- hasInnerMap: false,
163
- children() {
164
- return getChildren(this, newMapProvider);
165
- },
159
+ function createNode(nodeKey, parentNode) {
160
+ return {
161
+ nodeKey,
162
+ parentNode,
163
+ children: void 0,
166
164
  hasValue: false,
167
- value: { value: void 0 }
168
- });
169
- }
170
- function getChildren(node, newMapProvider) {
171
- node.hasInnerMap = true;
172
- return newMapProvider();
165
+ value: void 0
166
+ };
173
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.83.8",
3
+ "version": "0.83.9",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"