Module: Shared
- Included in:
- DataStructuresRMolinari::Algorithms, DataStructuresRMolinari::DisjointUnion, DataStructuresRMolinari::Heap, DataStructuresRMolinari::MaxPrioritySearchTree, DataStructuresRMolinari::MinPrioritySearchTree
- Defined in:
- lib/data_structures_rmolinari/shared.rb
Overview
Some odds and ends shared by other classes
Defined Under Namespace
Modules: BinaryTreeArithmetic Classes: DataError, InternalLogicError, LogicError, Point
Constant Summary collapse
- INFINITY =
Infinity without having to put a
Float::prefix every time Float::INFINITY
Instance Method Summary collapse
-
#contains_duplicates?(enum, by: nil) ⇒ Boolean
Simple O(n) check for duplicates in an enumerable.
Instance Method Details
#contains_duplicates?(enum, by: nil) ⇒ Boolean
Simple O(n) check for duplicates in an enumerable.
It may be worse than O(n), depending on how close to constant set insertion is.
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/data_structures_rmolinari/shared.rb', line 70 def contains_duplicates?(enum, by: nil) seen = Set.new enum.each do |v| v = v.send(by) if by return true if seen.include? v seen << v end false end |