Sha256: e512388f226ea85a4f68ab458008b919befad2e4931d0851aee745dd42b03125

Contents?: true

Size: 573 Bytes

Versions: 5

Compression:

Stored size: 573 Bytes

Contents

# adapted from https://github.com/bangthetable/CircularList

module Docket
  class RobinList
    def initialize(array)
      @array = array
    end

    def size
      @array.size
    end

    def list
      @array
    end

    def fetch_previous(index=0)
      index.nil? ? nil : @array.unshift(@array.pop)[index]
    end

    def fetch_next(index=0)
      index.nil? ? nil : @array.push(@array.shift)[index]
    end
    
    def fetch_after(e)
      fetch_next(@array.index(e))
    end
    
    def fetch_before(e)
      fetch_previous(@array.index(e))
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
docket-0.2.1 lib/docket/robin_list.rb
docket-0.2.0 lib/docket/robin_list.rb
docket-0.1.2 lib/docket/robin_list.rb
docket-0.1.1 lib/docket/robin_list.rb
docket-0.0.1 lib/docket/robin_list.rb