ordered_hash.cr

A simple ordered hash implementation for Crystal

OrderedHash

A Crystal class that acts as a Hash, but remembers the order of key inserts and returns the keys in that same order.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      ordered_hash:
        github: plambert/ordered_hash.cr
    
  2. Run shards install

Usage

require "ordered_hash"

hash = OrderedHash(String, String).new
hash["wednesday"] = "piano lesson"
hash["thursday"] = "guitar lesson"

hash.keys # ==> ["wednesday", "thursday"] # _always_ will return in this order!

new_hash = hash.sort
new_hash.keys # ==> ["thursday", "wednesday"] # the keys have been sorted, so will _always_ return in this order

Development

TODO: Write development instructions here

Contributing

  1. Fork it (https://github.com/plambert/ordered_hash.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

Repository

ordered_hash.cr

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 0
  • 21 days ago
  • June 18, 2025
License

MIT License

Links
Synced at

Tue, 08 Jul 2025 22:43:58 GMT

Languages