Sha256: 16fb3ca2b256469a7b2b6d922e2796777fbe6d8e780b29722c7dfdbc096599e6
Contents?: true
Size: 669 Bytes
Versions: 5
Compression:
Stored size: 669 Bytes
Contents
# frozen_string_literal: true module RnDB class Slice < Range # A range that knows how to sort and intersect itself, private to Thickets. def initialize(min, max) super(min.to_i, max.to_i) end # Just in case the Range implementation is inefficient. def count max - min + 1 end # Because Slices in a Thicket are disjoint, we can sort by min or max. def <=>(other) min <=> other.min end # We need to intersect slices when processing query constraints. def &(other) return nil if min > other.max || max < other.min self.class.new([min, other.min].max, [max, other.max].min) end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
rndb-0.3.1 | lib/rndb/slice.rb |
rndb-0.3.0 | lib/rndb/slice.rb |
rndb-0.2.1 | lib/rndb/slice.rb |
rndb-0.2.0 | lib/rndb/slice.rb |
rndb-0.1.1 | lib/rndb/slice.rb |