@bablr/btree 0.4.2 → 0.4.4
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/lib/enhanceable.js +20 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
package/lib/enhanceable.js
CHANGED
|
@@ -235,6 +235,10 @@ export const buildModule = (NODE_SIZE = defaultNodeSize, buildStats) => {
|
|
|
235
235
|
return size ? addAt(size, tree, value) : treeFromValues([value]);
|
|
236
236
|
};
|
|
237
237
|
|
|
238
|
+
const unshift = (value, tree) => {
|
|
239
|
+
return addAt(0, tree, value);
|
|
240
|
+
};
|
|
241
|
+
|
|
238
242
|
const collapses = (size) => {
|
|
239
243
|
return size < NODE_SIZE / 2 - 0.01;
|
|
240
244
|
};
|
|
@@ -293,6 +297,15 @@ export const buildModule = (NODE_SIZE = defaultNodeSize, buildStats) => {
|
|
|
293
297
|
values.splice(targetSibling === prevSibling ? values.length : 0, 0, donated);
|
|
294
298
|
|
|
295
299
|
returnValue = setValues(returnValue, values);
|
|
300
|
+
} else if (
|
|
301
|
+
getValues(prevSibling).length + values.length + getValues(nextSibling).length <=
|
|
302
|
+
NODE_SIZE
|
|
303
|
+
) {
|
|
304
|
+
returnValue = treeFromValues([
|
|
305
|
+
...getValues(prevSibling),
|
|
306
|
+
...values,
|
|
307
|
+
...getValues(nextSibling),
|
|
308
|
+
]);
|
|
296
309
|
}
|
|
297
310
|
}
|
|
298
311
|
|
|
@@ -324,6 +337,10 @@ export const buildModule = (NODE_SIZE = defaultNodeSize, buildStats) => {
|
|
|
324
337
|
return removeAt(-1, tree);
|
|
325
338
|
};
|
|
326
339
|
|
|
340
|
+
const shift = (tree) => {
|
|
341
|
+
return removeAt(0, tree);
|
|
342
|
+
};
|
|
343
|
+
|
|
327
344
|
const validateValues = (values) => {
|
|
328
345
|
if (values.length > NODE_SIZE) throw new Error();
|
|
329
346
|
if (!values.length) return;
|
|
@@ -546,10 +563,13 @@ export const buildModule = (NODE_SIZE = defaultNodeSize, buildStats) => {
|
|
|
546
563
|
collapses,
|
|
547
564
|
nodeCollapses,
|
|
548
565
|
nodeCanDonate,
|
|
566
|
+
unshift,
|
|
549
567
|
pop,
|
|
550
568
|
removeAt,
|
|
551
569
|
push,
|
|
552
570
|
addAt,
|
|
571
|
+
shift,
|
|
572
|
+
unshift,
|
|
553
573
|
concat,
|
|
554
574
|
isValidNode,
|
|
555
575
|
assertValidNode,
|
package/lib/index.js
CHANGED
package/package.json
CHANGED