MCPcopy Create free account
hub / github.com/nodejs/node / _TstNode

Class _TstNode

deps/undici/undici.js:1439–1540  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1437 headerNameLowerCasedRecord
1438 } = require_constants();
1439 var TstNode = class _TstNode {
1440 static {
1441 __name(this, "TstNode");
1442 }
1443 /** @type {any} */
1444 value = null;
1445 /** @type {null | TstNode} */
1446 left = null;
1447 /** @type {null | TstNode} */
1448 middle = null;
1449 /** @type {null | TstNode} */
1450 right = null;
1451 /** @type {number} */
1452 code;
1453 /**
1454 * @param {string} key
1455 * @param {any} value
1456 * @param {number} index
1457 */
1458 constructor(key, value, index) {
1459 if (index === void 0 || index >= key.length) {
1460 throw new TypeError("Unreachable");
1461 }
1462 const code = this.code = key.charCodeAt(index);
1463 if (code > 127) {
1464 throw new TypeError("key must be ascii string");
1465 }
1466 if (key.length !== ++index) {
1467 this.middle = new _TstNode(key, value, index);
1468 } else {
1469 this.value = value;
1470 }
1471 }
1472 /**
1473 * @param {string} key
1474 * @param {any} value
1475 * @returns {void}
1476 */
1477 add(key, value) {
1478 const length = key.length;
1479 if (length === 0) {
1480 throw new TypeError("Unreachable");
1481 }
1482 let index = 0;
1483 let node = this;
1484 while (true) {
1485 const code = key.charCodeAt(index);
1486 if (code > 127) {
1487 throw new TypeError("key must be ascii string");
1488 }
1489 if (node.code === code) {
1490 if (length === ++index) {
1491 node.value = value;
1492 break;
1493 } else if (node.middle !== null) {
1494 node = node.middle;
1495 } else {
1496 node.middle = new _TstNode(key, value, index);

Callers

nothing calls this directly

Calls 1

__nameFunction · 0.85

Tested by

no test coverage detected