github.com/plambert/ordered_hash.cr
main / published Jun 18, 2025 / repository
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
-
Add the dependency to your
shard.yml:dependencies: ordered_hash: github: plambert/ordered_hash.cr -
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
- Fork it (https://github.com/plambert/ordered_hash.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- Paul M. Lambert - creator and maintainer
API
- OrderedHash(K, V)
A class that acts both like a hash and an array, where the order of key insertion is remembered.