Lines Matching refs:node
44 RNode *find_next_node(const RNode *node, char c) { in find_next_node() argument
45 auto itr = std::lower_bound(std::begin(node->next), std::end(node->next), c, in find_next_node()
48 if (itr == std::end(node->next) || (*itr)->s[0] != c) { in find_next_node()
57 void add_next_node(RNode *node, std::unique_ptr<RNode> new_node) { in add_next_node() argument
58 auto itr = std::lower_bound(std::begin(node->next), std::end(node->next), in add_next_node()
62 node->next.insert(itr, std::move(new_node)); in add_next_node()
66 void Router::add_node(RNode *node, const char *pattern, size_t patlen, in add_node() argument
71 add_next_node(node, std::move(new_node)); in add_node()
82 auto node = &root_; in add_route() local
86 auto next_node = find_next_node(node, pattern[i]); in add_route()
88 add_node(node, pattern.c_str() + i, pattern.size() - i, index, in add_route()
93 node = next_node; in add_route()
97 auto n = std::min(node->len, slen); in add_route()
99 for (j = 0; j < n && node->s[j] == s[j]; ++j) in add_route()
103 if (slen == node->len) { in add_route()
106 if (node->index != -1) { in add_route()
108 return node->index; in add_route()
110 node->index = index; in add_route()
116 if (node->wildcard_index != -1) { in add_route()
117 return node->wildcard_index; in add_route()
119 node->wildcard_index = wildcard_index; in add_route()
123 if (slen > node->len) { in add_route()
131 if (node->len > j) { in add_route()
135 &node->s[j], node->len - j, node->index, node->wildcard_index); in add_route()
136 std::swap(node->next, new_node->next); in add_route()
138 node->len = j; in add_route()
139 node->index = -1; in add_route()
140 node->wildcard_index = -1; in add_route()
142 add_next_node(node, std::move(new_node)); in add_route()
145 node->index = index; in add_route()
146 node->wildcard_index = wildcard_index; in add_route()
154 add_node(node, pattern.c_str() + i, pattern.size() - i, index, in add_route()
162 const RNode *match_complete(size_t *offset, const RNode *node, in match_complete() argument
167 return node; in match_complete()
173 auto next_node = find_next_node(node, *p); in match_complete()
178 node = next_node; in match_complete()
180 auto n = std::min(node->len, static_cast<size_t>(last - p)); in match_complete()
181 if (memcmp(node->s, p, n) != 0) { in match_complete()
187 return node; in match_complete()
194 const RNode *match_partial(bool *pattern_is_wildcard, const RNode *node, in match_partial() argument
199 if (node->len == offset) { in match_partial()
200 return node; in match_partial()
210 auto n = std::min(node->len - offset, static_cast<size_t>(last - first)); in match_partial()
211 if (memcmp(node->s + offset, first, n) != 0) { in match_partial()
218 if (node->len == offset + n) { in match_partial()
219 if (node->index != -1) { in match_partial()
220 return node; in match_partial()
224 node = find_next_node(node, '/'); in match_partial()
225 if (node != nullptr && node->index != -1 && node->len == 1) { in match_partial()
226 return node; in match_partial()
233 if (node->index != -1 && offset + n + 1 == node->len && in match_partial()
234 node->s[node->len - 1] == '/') { in match_partial()
235 return node; in match_partial()
241 if (node->wildcard_index != -1) { in match_partial()
242 found_node = node; in match_partial()
244 } else if (node->index != -1 && node->s[node->len - 1] == '/') { in match_partial()
245 found_node = node; in match_partial()
249 assert(node->len == offset + n); in match_partial()
253 auto next_node = find_next_node(node, *p); in match_partial()
258 node = next_node; in match_partial()
260 auto n = std::min(node->len, static_cast<size_t>(last - p)); in match_partial()
261 if (memcmp(node->s, p, n) != 0) { in match_partial()
268 if (node->len == n) { in match_partial()
270 if (node->index != -1) { in match_partial()
272 return node; in match_partial()
276 node = find_next_node(node, '/'); in match_partial()
277 if (node != nullptr && node->index != -1 && node->len == 1) { in match_partial()
279 return node; in match_partial()
291 if (node->index != -1 && n + 1 == node->len && node->s[n] == '/') { in match_partial()
293 return node; in match_partial()
299 if (node->wildcard_index != -1) { in match_partial()
300 found_node = node; in match_partial()
302 } else if (node->index != -1 && node->s[node->len - 1] == '/') { in match_partial()
305 found_node = node; in match_partial()
309 assert(node->len == n); in match_partial()
315 const RNode *node; in match() local
318 node = match_complete(&offset, &root_, std::begin(host), std::end(host)); in match()
319 if (node == nullptr) { in match()
324 node = match_partial(&pattern_is_wildcard, node, offset, std::begin(path), in match()
326 if (node == nullptr || node == &root_) { in match()
330 return pattern_is_wildcard ? node->wildcard_index : node->index; in match()
334 const RNode *node; in match() local
337 node = match_complete(&offset, &root_, std::begin(s), std::end(s)); in match()
338 if (node == nullptr) { in match()
342 if (node->len != offset) { in match()
346 return node->index; in match()
350 const RNode *match_prefix(size_t *nread, const RNode *node, const char *first, in match_prefix() argument
359 auto next_node = find_next_node(node, *p); in match_prefix()
364 node = next_node; in match_prefix()
366 auto n = std::min(node->len, static_cast<size_t>(last - p)); in match_prefix()
367 if (memcmp(node->s, p, n) != 0) { in match_prefix()
374 if (node->index != -1) { in match_prefix()
376 return node; in match_prefix()
381 if (node->len == n) { in match_prefix()
383 return node; in match_prefix()
397 auto node = in match_prefix() local
399 if (node == nullptr) { in match_prefix()
403 *last_node = node; in match_prefix()
405 return node->index; in match_prefix()
409 void dump_node(const RNode *node, int depth) { in dump_node() argument
411 (int)node->len, node->s, node->len, node->index); in dump_node()
412 for (auto &nd : node->next) { in dump_node()