Git Product home page Git Product logo

bihash's People

Contributors

cohen-carlisle avatar

Stargazers

 avatar

Watchers

 avatar  avatar

bihash's Issues

missing methods

  • each_key
  • each_value
  • has_value?
  • index
  • invert
  • key
  • keys
  • rassoc
  • transform_values
  • transform_values!
  • value?
  • values

Implement merge methods?

Decide if Bihash should have merge methods.

If so, decide how to resolve collisions.

Merge methods:
#merge!
#update (alias of #merge!)
#merge

[#select, #select!, #keep_if] and [#reject, #reject!, #delete_if] redundancy vs efficiency

Suggested by Spike@StackExchange {

    def select!(&block)
      if block_given?
        raise_error_if_frozen
        old_size = size
        @forward.each { |k,v| delete(k) if !block.call(k,v) }
        old_size == size ? nil : self
      else
        to_enum(:select!)
      end
    end

The @forward.each line can be changed to keep_if(&block). Similarly for reject! and delete_if
}

However, this would also make redundant #block_given? and #raise_error_if_frozen checks

#rehash can leave Bihash in inconsistent state (thanks Spike@StackExchange)

found an edge case with rehash. Hash#rehash merges two pairs if their keys become equal, but not if their values become equal. Therefore the following code leaves a Bihash in an inconsistent state:

b = Bihash.new
key_a = ["a"]
key_b = ["b"]
key_c = ["c"]
b[key_a] = key_b
b[key_c] = key_c
key_a[0] = "c" # make key_a equal to key_c
b.rehash # @forward.size is now 1, but @reverse.size is still 2
puts b[["b"]].inspect # => ["c"] # found in @reverse
puts b[["c"]].inspect # => ["c"] # found in @forward

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.