Class: Dry::Validation::Rust::PathTrie

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/validation/rust/path_trie.rb

Instance Method Summary collapse

Constructor Details

#initializePathTrie

Returns a new instance of PathTrie.



10
11
12
# File 'lib/dry/validation/rust/path_trie.rb', line 10

def initialize
  @root = {}
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



38
39
40
# File 'lib/dry/validation/rust/path_trie.rb', line 38

def ==(other)
  other.is_a?(self.class) && @root == other.instance_variable_get(:@root)
end

#add(path) ⇒ Object



14
15
16
17
18
# File 'lib/dry/validation/rust/path_trie.rb', line 14

def add(path)
  node = @root
  path.each { |part| node = node[part] ||= {} }
  node[TERMINAL] = true
end

#freezeObject



33
34
35
36
# File 'lib/dry/validation/rust/path_trie.rb', line 33

def freeze
  freeze_node(@root)
  super
end

#hashObject



44
45
46
# File 'lib/dry/validation/rust/path_trie.rb', line 44

def hash
  @root.hash
end

#prefix?(path) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dry/validation/rust/path_trie.rb', line 20

def prefix?(path)
  return false if path.empty?

  node = @root
  path.each do |part|
    return true if node.key?(TERMINAL)

    node = node[part]
    return false unless node
  end
  true
end