class Wordlist::UniqueFilter
Acts as a filter to filter out duplicate words.
@api semipublic
@since 1.0.0
Attributes
hashes[R]
The seen String hashes
@return [Set<Integer>]
Public Class Methods
new()
click to toggle source
Creates a new unique filter.
# File lib/wordlist/unique_filter.rb, line 22 def initialize @hashes = Set.new end
Public Instance Methods
add(word)
click to toggle source
Adds the word to the unique filter.
@param [String] word
The word to add.
# File lib/wordlist/unique_filter.rb, line 45 def add(word) @hashes.add(word.hash) end
Also aliased as: <<
add?(word)
click to toggle source
Attempts to add the word to the unique filter.
@param [String] word
The word to add.
@return [Boolean]
Returns `true` if the word does not yet exist in the unique filter. Returns `false` if the word already exists in the unique filter.
# File lib/wordlist/unique_filter.rb, line 61 def add?(word) !@hashes.add?(word.hash).nil? end
clear()
click to toggle source
Clears the unique filter.
# File lib/wordlist/unique_filter.rb, line 77 def clear @hashes.clear end
empty?()
click to toggle source
Determines if the unique filter is empty or not.
@return [Boolean]
# File lib/wordlist/unique_filter.rb, line 70 def empty? @hashes.empty? end
include?(word)
click to toggle source
Determines if the given word has been previously seen.
@param [String] word
The word to check for.
@return [Boolean]
Specifies whether the word has been previously seen.
# File lib/wordlist/unique_filter.rb, line 35 def include?(word) @hashes.include?(word.hash) end
size()
click to toggle source
The size of the unique filter.
@return [Integer]
The number of unique words seen by the unique filter.
# File lib/wordlist/unique_filter.rb, line 87 def size @hashes.size end