| 26 | namespace internal { |
| 27 | |
| 28 | Status Trie::Validate() const { |
| 29 | const auto n_nodes = static_cast<fast_index_type>(nodes_.size()); |
| 30 | if (size_ > n_nodes) { |
| 31 | return Status::Invalid("Number of entries larger than number of nodes"); |
| 32 | } |
| 33 | for (const auto& node : nodes_) { |
| 34 | if (node.found_index_ >= size_) { |
| 35 | return Status::Invalid("Found index >= size"); |
| 36 | } |
| 37 | if (node.child_lookup_ != -1 && |
| 38 | node.child_lookup_ * 256 > |
| 39 | static_cast<fast_index_type>(lookup_table_.size() - 256)) { |
| 40 | return Status::Invalid("Child lookup base doesn't point to 256 valid indices"); |
| 41 | } |
| 42 | } |
| 43 | for (const auto index : lookup_table_) { |
| 44 | if (index >= n_nodes) { |
| 45 | return Status::Invalid("Child lookup index out of bounds"); |
| 46 | } |
| 47 | } |
| 48 | return Status::OK(); |
| 49 | } |
| 50 | |
| 51 | void Trie::Dump(const Node* node, const std::string& indent) const { |
| 52 | std::cerr << "[\"" << node->substring_ << "\"]"; |