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

Method search

deps/undici/src/lib/core/tree.js:91–121  ·  view source on GitHub ↗

* @param {Uint8Array} key * @returns {TstNode | null}

(key)

Source from the content-addressed store, hash-verified

89 * @returns {TstNode | null}
90 */
91 search (key) {
92 const keylength = key.length
93 let index = 0
94 /**
95 * @type {TstNode|null}
96 */
97 let node = this
98 while (node !== null && index < keylength) {
99 let code = key[index]
100 // A-Z
101 // First check if it is bigger than 0x5a.
102 // Lowercase letters have higher char codes than uppercase ones.
103 // Also we assume that headers will mostly contain lowercase characters.
104 if (code <= 0x5a && code >= 0x41) {
105 // Lowercase for uppercase.
106 code |= 32
107 }
108 while (node !== null) {
109 if (code === node.code) {
110 if (keylength === ++index) {
111 // Returns Node since it is the last key.
112 return node
113 }
114 node = node.middle
115 break
116 }
117 node = node.code < code ? node.left : node.right
118 }
119 }
120 return null
121 }
122}
123
124class TernarySearchTree {

Callers 1

lookupMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected