hamster 0.4.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/hamster.rb +11 -9
- data/lib/hamster/core_ext.rb +2 -3
- data/lib/hamster/core_ext/enumerable.rb +18 -27
- data/lib/hamster/core_ext/io.rb +16 -25
- data/lib/hamster/deque.rb +252 -0
- data/lib/hamster/enumerable.rb +123 -112
- data/lib/hamster/experimental/mutable_queue.rb +5 -14
- data/lib/hamster/experimental/mutable_set.rb +7 -14
- data/lib/hamster/hash.rb +732 -102
- data/lib/hamster/immutable.rb +4 -10
- data/lib/hamster/list.rb +1155 -215
- data/lib/hamster/{experimental/mutable_hash.rb → mutable_hash.rb} +11 -14
- data/lib/hamster/nested.rb +36 -0
- data/lib/hamster/{experimental/read_copy_update.rb → read_copy_update.rb} +10 -8
- data/lib/hamster/set.rb +488 -90
- data/lib/hamster/sorted_set.rb +1397 -0
- data/lib/hamster/trie.rb +210 -65
- data/lib/hamster/undefined.rb +1 -7
- data/lib/hamster/vector.rb +1329 -83
- data/lib/hamster/version.rb +1 -3
- data/spec/{hamster/core_ext → fixtures}/io_spec.txt +0 -0
- data/spec/lib/hamster/core_ext/array_spec.rb +14 -0
- data/spec/lib/hamster/core_ext/enumerable_spec.rb +30 -0
- data/spec/lib/hamster/core_ext/io_spec.rb +29 -0
- data/spec/lib/hamster/deque/clear_spec.rb +34 -0
- data/spec/lib/hamster/deque/construction_spec.rb +30 -0
- data/spec/lib/hamster/deque/copying_spec.rb +20 -0
- data/spec/lib/hamster/deque/dequeue_spec.rb +35 -0
- data/spec/lib/hamster/deque/empty_spec.rb +40 -0
- data/spec/lib/hamster/deque/enqueue_spec.rb +28 -0
- data/spec/lib/hamster/deque/first_spec.rb +18 -0
- data/spec/lib/hamster/deque/inspect_spec.rb +24 -0
- data/spec/lib/hamster/deque/last_spec.rb +18 -0
- data/spec/lib/hamster/deque/marshal_spec.rb +34 -0
- data/spec/lib/hamster/deque/new_spec.rb +44 -0
- data/spec/lib/hamster/deque/pop_spec.rb +33 -0
- data/spec/lib/hamster/deque/pretty_print_spec.rb +24 -0
- data/spec/lib/hamster/deque/random_modification_spec.rb +34 -0
- data/spec/lib/hamster/deque/size_spec.rb +20 -0
- data/spec/lib/hamster/deque/to_a_spec.rb +27 -0
- data/spec/lib/hamster/deque/to_ary_spec.rb +36 -0
- data/spec/lib/hamster/deque/to_list_spec.rb +26 -0
- data/spec/lib/hamster/deque/unshift_spec.rb +26 -0
- data/spec/lib/hamster/experimental/mutable_set/add_qm_spec.rb +39 -0
- data/spec/lib/hamster/experimental/mutable_set/add_spec.rb +37 -0
- data/spec/lib/hamster/experimental/mutable_set/delete_qm_spec.rb +38 -0
- data/spec/lib/hamster/experimental/mutable_set/delete_spec.rb +37 -0
- data/spec/lib/hamster/hash/all_spec.rb +54 -0
- data/spec/lib/hamster/hash/any_spec.rb +54 -0
- data/spec/lib/hamster/hash/assoc_spec.rb +52 -0
- data/spec/lib/hamster/hash/clear_spec.rb +43 -0
- data/spec/lib/hamster/hash/construction_spec.rb +39 -0
- data/spec/lib/hamster/hash/copying_spec.rb +14 -0
- data/spec/lib/hamster/hash/default_proc_spec.rb +73 -0
- data/spec/lib/hamster/hash/delete_spec.rb +40 -0
- data/spec/lib/hamster/hash/each_spec.rb +78 -0
- data/spec/lib/hamster/hash/each_with_index_spec.rb +30 -0
- data/spec/lib/hamster/hash/empty_spec.rb +44 -0
- data/spec/lib/hamster/hash/eql_spec.rb +70 -0
- data/spec/lib/hamster/hash/except_spec.rb +43 -0
- data/spec/lib/hamster/hash/fetch_spec.rb +58 -0
- data/spec/lib/hamster/hash/find_spec.rb +44 -0
- data/spec/lib/hamster/hash/flat_map_spec.rb +36 -0
- data/spec/lib/hamster/hash/flatten_spec.rb +99 -0
- data/spec/lib/hamster/hash/get_spec.rb +80 -0
- data/spec/lib/hamster/hash/has_key_spec.rb +32 -0
- data/spec/lib/hamster/hash/has_value_spec.rb +28 -0
- data/spec/lib/hamster/hash/hash_spec.rb +30 -0
- data/spec/{hamster → lib/hamster}/hash/immutable_spec.rb +3 -6
- data/spec/lib/hamster/hash/inspect_spec.rb +31 -0
- data/spec/lib/hamster/hash/invert_spec.rb +31 -0
- data/spec/lib/hamster/hash/key_spec.rb +28 -0
- data/spec/lib/hamster/hash/keys_spec.rb +17 -0
- data/spec/lib/hamster/hash/map_spec.rb +46 -0
- data/spec/lib/hamster/hash/marshal_spec.rb +29 -0
- data/spec/lib/hamster/hash/merge_spec.rb +83 -0
- data/spec/lib/hamster/hash/min_max_spec.rb +46 -0
- data/spec/lib/hamster/hash/new_spec.rb +71 -0
- data/spec/lib/hamster/hash/none_spec.rb +49 -0
- data/spec/lib/hamster/hash/partition_spec.rb +36 -0
- data/spec/lib/hamster/hash/pretty_print_spec.rb +35 -0
- data/spec/lib/hamster/hash/put_spec.rb +103 -0
- data/spec/lib/hamster/hash/reduce_spec.rb +36 -0
- data/spec/lib/hamster/hash/reject_spec.rb +62 -0
- data/spec/lib/hamster/hash/reverse_each_spec.rb +28 -0
- data/spec/lib/hamster/hash/sample_spec.rb +14 -0
- data/spec/lib/hamster/hash/select_spec.rb +58 -0
- data/spec/{hamster → lib/hamster}/hash/size_spec.rb +9 -18
- data/spec/lib/hamster/hash/slice_spec.rb +45 -0
- data/spec/lib/hamster/hash/sort_spec.rb +27 -0
- data/spec/lib/hamster/hash/store_spec.rb +76 -0
- data/spec/lib/hamster/hash/take_spec.rb +36 -0
- data/spec/lib/hamster/hash/to_a_spec.rb +14 -0
- data/spec/lib/hamster/hash/to_hash_spec.rb +22 -0
- data/spec/lib/hamster/hash/update_in_spec.rb +80 -0
- data/spec/lib/hamster/hash/values_at_spec.rb +14 -0
- data/spec/lib/hamster/hash/values_spec.rb +25 -0
- data/spec/{hamster → lib/hamster}/immutable/copying_spec.rb +3 -10
- data/spec/{hamster → lib/hamster}/immutable/immutable_spec.rb +3 -16
- data/spec/lib/hamster/immutable/memoize_spec.rb +56 -0
- data/spec/lib/hamster/immutable/new_spec.rb +14 -0
- data/spec/lib/hamster/immutable/transform_spec.rb +26 -0
- data/spec/lib/hamster/immutable/transform_unless_spec.rb +44 -0
- data/spec/lib/hamster/list/add_spec.rb +26 -0
- data/spec/lib/hamster/list/all_spec.rb +58 -0
- data/spec/lib/hamster/list/any_spec.rb +50 -0
- data/spec/lib/hamster/list/append_spec.rb +39 -0
- data/spec/lib/hamster/list/at_spec.rb +30 -0
- data/spec/lib/hamster/list/break_spec.rb +70 -0
- data/spec/lib/hamster/list/cadr_spec.rb +39 -0
- data/spec/lib/hamster/list/chunk_spec.rb +29 -0
- data/spec/lib/hamster/list/clear_spec.rb +25 -0
- data/spec/lib/hamster/list/combination_spec.rb +34 -0
- data/spec/lib/hamster/list/compact_spec.rb +35 -0
- data/spec/lib/hamster/list/compare_spec.rb +31 -0
- data/spec/lib/hamster/list/cons_spec.rb +26 -0
- data/spec/lib/hamster/list/construction_spec.rb +111 -0
- data/spec/lib/hamster/list/copying_spec.rb +20 -0
- data/spec/lib/hamster/list/count_spec.rb +37 -0
- data/spec/lib/hamster/list/cycle_spec.rb +29 -0
- data/spec/lib/hamster/list/delete_at_spec.rb +19 -0
- data/spec/lib/hamster/list/delete_spec.rb +17 -0
- data/spec/lib/hamster/list/drop_spec.rb +31 -0
- data/spec/lib/hamster/list/drop_while_spec.rb +39 -0
- data/spec/lib/hamster/list/each_slice_spec.rb +52 -0
- data/spec/lib/hamster/list/each_spec.rb +41 -0
- data/spec/lib/hamster/list/each_with_index_spec.rb +29 -0
- data/spec/lib/hamster/list/empty_spec.rb +24 -0
- data/spec/lib/hamster/list/eql_spec.rb +62 -0
- data/spec/lib/hamster/list/fill_spec.rb +50 -0
- data/spec/lib/hamster/list/find_all_spec.rb +71 -0
- data/spec/{hamster → lib/hamster}/list/find_index_spec.rb +7 -29
- data/spec/{hamster → lib/hamster}/list/find_spec.rb +13 -35
- data/spec/lib/hamster/list/flat_map_spec.rb +52 -0
- data/spec/lib/hamster/list/flatten_spec.rb +31 -0
- data/spec/lib/hamster/list/grep_spec.rb +47 -0
- data/spec/lib/hamster/list/group_by_spec.rb +42 -0
- data/spec/lib/hamster/list/hash_spec.rb +22 -0
- data/spec/{hamster → lib/hamster}/list/head_spec.rb +6 -21
- data/spec/{hamster → lib/hamster}/list/include_spec.rb +8 -29
- data/spec/lib/hamster/list/index_spec.rb +34 -0
- data/spec/lib/hamster/list/indices_spec.rb +62 -0
- data/spec/lib/hamster/list/init_spec.rb +29 -0
- data/spec/lib/hamster/list/inits_spec.rb +29 -0
- data/spec/lib/hamster/list/insert_spec.rb +47 -0
- data/spec/lib/hamster/list/inspect_spec.rb +30 -0
- data/spec/lib/hamster/list/intersperse_spec.rb +29 -0
- data/spec/lib/hamster/list/join_spec.rb +64 -0
- data/spec/lib/hamster/list/last_spec.rb +24 -0
- data/spec/lib/hamster/list/ltlt_spec.rb +20 -0
- data/spec/lib/hamster/list/map_spec.rb +46 -0
- data/spec/lib/hamster/list/maximum_spec.rb +40 -0
- data/spec/{hamster → lib/hamster}/list/merge_by_spec.rb +9 -36
- data/spec/{hamster → lib/hamster}/list/merge_spec.rb +5 -24
- data/spec/lib/hamster/list/minimum_spec.rb +40 -0
- data/spec/lib/hamster/list/multithreading_spec.rb +48 -0
- data/spec/{hamster → lib/hamster}/list/none_spec.rb +14 -41
- data/spec/{hamster → lib/hamster}/list/one_spec.rb +15 -40
- data/spec/lib/hamster/list/partition_spec.rb +116 -0
- data/spec/lib/hamster/list/permutation_spec.rb +56 -0
- data/spec/lib/hamster/list/pop_spec.rb +26 -0
- data/spec/lib/hamster/list/product_spec.rb +24 -0
- data/spec/lib/hamster/list/reduce_spec.rb +54 -0
- data/spec/lib/hamster/list/reject_spec.rb +46 -0
- data/spec/lib/hamster/list/reverse_spec.rb +35 -0
- data/spec/lib/hamster/list/rotate_spec.rb +37 -0
- data/spec/lib/hamster/list/sample_spec.rb +14 -0
- data/spec/lib/hamster/list/select_spec.rb +71 -0
- data/spec/lib/hamster/list/size_spec.rb +26 -0
- data/spec/lib/hamster/list/slice_spec.rb +230 -0
- data/spec/lib/hamster/list/sorting_spec.rb +47 -0
- data/spec/lib/hamster/list/span_spec.rb +77 -0
- data/spec/lib/hamster/list/split_at_spec.rb +44 -0
- data/spec/lib/hamster/list/subsequences_spec.rb +24 -0
- data/spec/lib/hamster/list/sum_spec.rb +24 -0
- data/spec/lib/hamster/list/tail_spec.rb +31 -0
- data/spec/lib/hamster/list/tails_spec.rb +29 -0
- data/spec/lib/hamster/list/take_spec.rb +31 -0
- data/spec/lib/hamster/list/take_while_spec.rb +47 -0
- data/spec/lib/hamster/list/to_a_spec.rb +40 -0
- data/spec/lib/hamster/list/to_ary_spec.rb +42 -0
- data/spec/lib/hamster/list/to_list_spec.rb +20 -0
- data/spec/lib/hamster/list/to_set_spec.rb +19 -0
- data/spec/lib/hamster/list/transpose_spec.rb +20 -0
- data/spec/lib/hamster/list/union_spec.rb +32 -0
- data/spec/lib/hamster/list/uniq_spec.rb +30 -0
- data/spec/lib/hamster/list/zip_spec.rb +24 -0
- data/spec/lib/hamster/nested/construction_spec.rb +44 -0
- data/spec/lib/hamster/set/add_spec.rb +76 -0
- data/spec/lib/hamster/set/all_spec.rb +52 -0
- data/spec/lib/hamster/set/any_spec.rb +52 -0
- data/spec/lib/hamster/set/clear_spec.rb +34 -0
- data/spec/{hamster → lib/hamster}/set/compact_spec.rb +9 -20
- data/spec/lib/hamster/set/construction_spec.rb +19 -0
- data/spec/lib/hamster/set/copying_spec.rb +14 -0
- data/spec/lib/hamster/set/count_spec.rb +37 -0
- data/spec/lib/hamster/set/delete_spec.rb +72 -0
- data/spec/lib/hamster/set/difference_spec.rb +50 -0
- data/spec/lib/hamster/set/disjoint_spec.rb +26 -0
- data/spec/lib/hamster/set/each_spec.rb +46 -0
- data/spec/lib/hamster/set/empty_spec.rb +45 -0
- data/spec/lib/hamster/set/eqeq_spec.rb +104 -0
- data/spec/lib/hamster/set/eql_spec.rb +110 -0
- data/spec/lib/hamster/set/exclusion_spec.rb +48 -0
- data/spec/{hamster → lib/hamster}/set/find_spec.rb +10 -27
- data/spec/lib/hamster/set/first_spec.rb +29 -0
- data/spec/lib/hamster/set/flatten_spec.rb +47 -0
- data/spec/lib/hamster/set/grep_spec.rb +58 -0
- data/spec/lib/hamster/set/group_by_spec.rb +60 -0
- data/spec/lib/hamster/set/hash_spec.rb +23 -0
- data/spec/{hamster → lib/hamster}/set/immutable_spec.rb +4 -7
- data/spec/lib/hamster/set/include_spec.rb +61 -0
- data/spec/lib/hamster/set/inspect_spec.rb +48 -0
- data/spec/lib/hamster/set/intersect_spec.rb +26 -0
- data/spec/lib/hamster/set/intersection_spec.rb +53 -0
- data/spec/lib/hamster/set/join_spec.rb +65 -0
- data/spec/lib/hamster/set/map_spec.rb +60 -0
- data/spec/lib/hamster/set/marshal_spec.rb +29 -0
- data/spec/lib/hamster/set/maximum_spec.rb +37 -0
- data/spec/lib/hamster/set/minimum_spec.rb +37 -0
- data/spec/lib/hamster/set/new_spec.rb +54 -0
- data/spec/{hamster → lib/hamster}/set/none_spec.rb +17 -32
- data/spec/{hamster → lib/hamster}/set/one_spec.rb +16 -31
- data/spec/lib/hamster/set/partition_spec.rb +53 -0
- data/spec/lib/hamster/set/product_spec.rb +24 -0
- data/spec/lib/hamster/set/reduce_spec.rb +56 -0
- data/spec/lib/hamster/set/reject_spec.rb +51 -0
- data/spec/lib/hamster/set/reverse_each_spec.rb +39 -0
- data/spec/lib/hamster/set/sample_spec.rb +14 -0
- data/spec/lib/hamster/set/select_spec.rb +74 -0
- data/spec/{hamster → lib/hamster}/set/size_spec.rb +4 -13
- data/spec/lib/hamster/set/sorting_spec.rb +49 -0
- data/spec/lib/hamster/set/subset_spec.rb +52 -0
- data/spec/lib/hamster/set/sum_spec.rb +24 -0
- data/spec/lib/hamster/set/superset_spec.rb +52 -0
- data/spec/lib/hamster/set/to_a_spec.rb +31 -0
- data/spec/lib/hamster/set/to_list_spec.rb +37 -0
- data/spec/lib/hamster/set/to_set_spec.rb +20 -0
- data/spec/lib/hamster/set/union_spec.rb +64 -0
- data/spec/lib/hamster/sorted_set/above_spec.rb +52 -0
- data/spec/lib/hamster/sorted_set/add_spec.rb +63 -0
- data/spec/lib/hamster/sorted_set/at_spec.rb +25 -0
- data/spec/lib/hamster/sorted_set/below_spec.rb +52 -0
- data/spec/lib/hamster/sorted_set/between_spec.rb +52 -0
- data/spec/lib/hamster/sorted_set/clear_spec.rb +44 -0
- data/spec/lib/hamster/sorted_set/construction_spec.rb +29 -0
- data/spec/lib/hamster/sorted_set/delete_at_spec.rb +19 -0
- data/spec/lib/hamster/sorted_set/delete_spec.rb +90 -0
- data/spec/lib/hamster/sorted_set/difference_spec.rb +23 -0
- data/spec/lib/hamster/sorted_set/disjoint_spec.rb +26 -0
- data/spec/lib/hamster/sorted_set/drop_spec.rb +56 -0
- data/spec/lib/hamster/sorted_set/drop_while_spec.rb +35 -0
- data/spec/lib/hamster/sorted_set/each_spec.rb +29 -0
- data/spec/lib/hamster/sorted_set/empty_spec.rb +35 -0
- data/spec/lib/hamster/sorted_set/eql_spec.rb +121 -0
- data/spec/lib/hamster/sorted_set/exclusion_spec.rb +23 -0
- data/spec/lib/hamster/sorted_set/fetch_spec.rb +65 -0
- data/spec/lib/hamster/sorted_set/find_index_spec.rb +41 -0
- data/spec/lib/hamster/sorted_set/first_spec.rb +19 -0
- data/spec/lib/hamster/sorted_set/from_spec.rb +52 -0
- data/spec/lib/hamster/sorted_set/group_by_spec.rb +58 -0
- data/spec/lib/hamster/sorted_set/include_spec.rb +24 -0
- data/spec/lib/hamster/sorted_set/inspect_spec.rb +38 -0
- data/spec/lib/hamster/sorted_set/intersect_spec.rb +26 -0
- data/spec/lib/hamster/sorted_set/intersection_spec.rb +29 -0
- data/spec/lib/hamster/sorted_set/last_spec.rb +37 -0
- data/spec/lib/hamster/sorted_set/map_spec.rb +36 -0
- data/spec/lib/hamster/sorted_set/marshal_spec.rb +37 -0
- data/spec/lib/hamster/sorted_set/maximum_spec.rb +37 -0
- data/spec/lib/hamster/sorted_set/minimum_spec.rb +20 -0
- data/spec/lib/hamster/sorted_set/new_spec.rb +52 -0
- data/spec/lib/hamster/sorted_set/reverse_each_spec.rb +29 -0
- data/spec/lib/hamster/sorted_set/sample_spec.rb +14 -0
- data/spec/lib/hamster/sorted_set/select_spec.rb +62 -0
- data/spec/{hamster/vector → lib/hamster/sorted_set}/size_spec.rb +6 -15
- data/spec/lib/hamster/sorted_set/slice_spec.rb +257 -0
- data/spec/lib/hamster/sorted_set/sorting_spec.rb +45 -0
- data/spec/lib/hamster/sorted_set/subset_spec.rb +48 -0
- data/spec/lib/hamster/sorted_set/superset_spec.rb +48 -0
- data/spec/lib/hamster/sorted_set/take_spec.rb +55 -0
- data/spec/lib/hamster/sorted_set/take_while_spec.rb +34 -0
- data/spec/lib/hamster/sorted_set/to_set_spec.rb +19 -0
- data/spec/lib/hamster/sorted_set/union_spec.rb +28 -0
- data/spec/lib/hamster/sorted_set/up_to_spec.rb +52 -0
- data/spec/lib/hamster/sorted_set/values_at_spec.rb +34 -0
- data/spec/lib/hamster/vector/add_spec.rb +68 -0
- data/spec/lib/hamster/vector/any_spec.rb +70 -0
- data/spec/lib/hamster/vector/assoc_spec.rb +36 -0
- data/spec/lib/hamster/vector/bsearch_spec.rb +58 -0
- data/spec/lib/hamster/vector/clear_spec.rb +34 -0
- data/spec/lib/hamster/vector/combination_spec.rb +82 -0
- data/spec/lib/hamster/vector/compact_spec.rb +30 -0
- data/spec/lib/hamster/vector/compare_spec.rb +32 -0
- data/spec/lib/hamster/vector/concat_spec.rb +35 -0
- data/spec/lib/hamster/vector/copying_spec.rb +21 -0
- data/spec/lib/hamster/vector/count_spec.rb +18 -0
- data/spec/lib/hamster/vector/delete_at_spec.rb +54 -0
- data/spec/lib/hamster/vector/delete_spec.rb +31 -0
- data/spec/lib/hamster/vector/drop_spec.rb +42 -0
- data/spec/lib/hamster/vector/drop_while_spec.rb +55 -0
- data/spec/lib/hamster/vector/each_index_spec.rb +41 -0
- data/spec/lib/hamster/vector/each_spec.rb +45 -0
- data/spec/lib/hamster/vector/each_with_index_spec.rb +40 -0
- data/spec/lib/hamster/vector/empty_spec.rb +42 -0
- data/spec/lib/hamster/vector/eql_spec.rb +77 -0
- data/spec/lib/hamster/vector/fetch_spec.rb +65 -0
- data/spec/lib/hamster/vector/fill_spec.rb +89 -0
- data/spec/lib/hamster/vector/first_spec.rb +19 -0
- data/spec/lib/hamster/vector/flat_map_spec.rb +51 -0
- data/spec/lib/hamster/vector/flatten_spec.rb +44 -0
- data/spec/lib/hamster/vector/get_spec.rb +75 -0
- data/spec/lib/hamster/vector/group_by_spec.rb +58 -0
- data/spec/{hamster → lib/hamster}/vector/include_spec.rb +6 -20
- data/spec/lib/hamster/vector/insert_spec.rb +69 -0
- data/spec/lib/hamster/vector/inspect_spec.rb +50 -0
- data/spec/{hamster/set → lib/hamster/vector}/join_spec.rb +24 -34
- data/spec/lib/hamster/vector/last_spec.rb +46 -0
- data/spec/lib/hamster/vector/length_spec.rb +46 -0
- data/spec/lib/hamster/vector/ltlt_spec.rb +66 -0
- data/spec/lib/hamster/vector/map_spec.rb +52 -0
- data/spec/lib/hamster/vector/marshal_spec.rb +32 -0
- data/spec/lib/hamster/vector/maximum_spec.rb +34 -0
- data/spec/lib/hamster/vector/minimum_spec.rb +34 -0
- data/spec/lib/hamster/vector/multiply_spec.rb +48 -0
- data/spec/lib/hamster/vector/new_spec.rb +51 -0
- data/spec/lib/hamster/vector/partition_spec.rb +53 -0
- data/spec/lib/hamster/vector/permutation_spec.rb +92 -0
- data/spec/lib/hamster/vector/pop_spec.rb +27 -0
- data/spec/lib/hamster/vector/product_spec.rb +71 -0
- data/spec/{hamster → lib/hamster}/vector/reduce_spec.rb +18 -49
- data/spec/lib/hamster/vector/reject_spec.rb +44 -0
- data/spec/lib/hamster/vector/repeated_combination_spec.rb +78 -0
- data/spec/lib/hamster/vector/repeated_permutation_spec.rb +94 -0
- data/spec/lib/hamster/vector/reverse_each_spec.rb +32 -0
- data/spec/lib/hamster/vector/reverse_spec.rb +22 -0
- data/spec/lib/hamster/vector/rindex_spec.rb +37 -0
- data/spec/lib/hamster/vector/rotate_spec.rb +74 -0
- data/spec/lib/hamster/vector/sample_spec.rb +14 -0
- data/spec/lib/hamster/vector/select_spec.rb +64 -0
- data/spec/lib/hamster/vector/set_spec.rb +175 -0
- data/spec/lib/hamster/vector/shift_spec.rb +28 -0
- data/spec/lib/hamster/vector/shuffle_spec.rb +44 -0
- data/spec/lib/hamster/vector/slice_spec.rb +241 -0
- data/spec/lib/hamster/vector/sorting_spec.rb +57 -0
- data/spec/{hamster/set → lib/hamster/vector}/sum_spec.rb +5 -19
- data/spec/lib/hamster/vector/take_spec.rb +43 -0
- data/spec/lib/hamster/vector/take_while_spec.rb +35 -0
- data/spec/lib/hamster/vector/to_a_spec.rb +42 -0
- data/spec/lib/hamster/vector/to_ary_spec.rb +35 -0
- data/spec/lib/hamster/vector/to_list_spec.rb +32 -0
- data/spec/lib/hamster/vector/to_set_spec.rb +23 -0
- data/spec/lib/hamster/vector/transpose_spec.rb +49 -0
- data/spec/lib/hamster/vector/uniq_spec.rb +56 -0
- data/spec/lib/hamster/vector/unshift_spec.rb +29 -0
- data/spec/lib/hamster/vector/update_in_spec.rb +83 -0
- data/spec/lib/hamster/vector/values_at_spec.rb +34 -0
- data/spec/lib/hamster/vector/zip_spec.rb +58 -0
- data/spec/spec_helper.rb +45 -13
- metadata +807 -458
- data/History.rdoc +0 -419
- data/LICENSE +0 -20
- data/README.rdoc +0 -236
- data/Rakefile +0 -5
- data/lib/hamster/core_ext/enumerator.rb +0 -30
- data/lib/hamster/experimental/mutable_stack.rb +0 -35
- data/lib/hamster/queue.rb +0 -93
- data/lib/hamster/sorter.rb +0 -32
- data/lib/hamster/stack.rb +0 -82
- data/lib/hamster/tuple.rb +0 -45
- data/spec/hamster/core_ext/array_spec.rb +0 -20
- data/spec/hamster/core_ext/coverage/assets/0.4.4/app.js +0 -66
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/blank.gif +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_close.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_loading.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_nav_left.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_nav_right.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_shadow_e.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_shadow_n.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_shadow_ne.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_shadow_nw.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_shadow_s.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_shadow_se.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_shadow_sw.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_shadow_w.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_title_left.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_title_main.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_title_over.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancy_title_right.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancybox-x.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancybox-y.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/fancybox.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/jquery.fancybox-1.3.1.css +0 -363
- data/spec/hamster/core_ext/coverage/assets/0.4.4/fancybox/jquery.fancybox-1.3.1.pack.js +0 -44
- data/spec/hamster/core_ext/coverage/assets/0.4.4/favicon.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/jquery-1.4.2.min.js +0 -155
- data/spec/hamster/core_ext/coverage/assets/0.4.4/jquery.dataTables.min.js +0 -152
- data/spec/hamster/core_ext/coverage/assets/0.4.4/jquery.timeago.js +0 -141
- data/spec/hamster/core_ext/coverage/assets/0.4.4/jquery.url.js +0 -174
- data/spec/hamster/core_ext/coverage/assets/0.4.4/loading.gif +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/magnify.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/spec/hamster/core_ext/coverage/assets/0.4.4/smoothness/jquery-ui-1.8.4.custom.css +0 -295
- data/spec/hamster/core_ext/coverage/assets/0.4.4/stylesheet.css +0 -341
- data/spec/hamster/core_ext/coverage/covered_percent +0 -1
- data/spec/hamster/core_ext/coverage/index.html +0 -71
- data/spec/hamster/core_ext/coverage/resultset.yml +0 -10
- data/spec/hamster/core_ext/enumerable_spec.rb +0 -34
- data/spec/hamster/core_ext/enumerator_spec.rb +0 -25
- data/spec/hamster/core_ext/io_spec.rb +0 -29
- data/spec/hamster/experimental/mutable_set/add?_spec.rb +0 -47
- data/spec/hamster/experimental/mutable_set/add_spec.rb +0 -51
- data/spec/hamster/experimental/mutable_set/delete?_spec.rb +0 -47
- data/spec/hamster/experimental/mutable_set/delete_spec.rb +0 -47
- data/spec/hamster/experimental/mutable_stack/pop_spec.rb +0 -41
- data/spec/hamster/experimental/mutable_stack/push_spec.rb +0 -41
- data/spec/hamster/hash/all_spec.rb +0 -59
- data/spec/hamster/hash/any_spec.rb +0 -68
- data/spec/hamster/hash/clear_spec.rb +0 -36
- data/spec/hamster/hash/construction_spec.rb +0 -35
- data/spec/hamster/hash/copying_spec.rb +0 -23
- data/spec/hamster/hash/delete_spec.rb +0 -47
- data/spec/hamster/hash/each_spec.rb +0 -41
- data/spec/hamster/hash/empty_spec.rb +0 -27
- data/spec/hamster/hash/eql_spec.rb +0 -62
- data/spec/hamster/hash/except_spec.rb +0 -31
- data/spec/hamster/hash/fetch_spec.rb +0 -95
- data/spec/hamster/hash/filter_spec.rb +0 -63
- data/spec/hamster/hash/find_spec.rb +0 -58
- data/spec/hamster/hash/get_spec.rb +0 -68
- data/spec/hamster/hash/has_key_spec.rb +0 -35
- data/spec/hamster/hash/hash_spec.rb +0 -54
- data/spec/hamster/hash/inspect_spec.rb +0 -32
- data/spec/hamster/hash/keys_spec.rb +0 -21
- data/spec/hamster/hash/map_spec.rb +0 -64
- data/spec/hamster/hash/merge_spec.rb +0 -36
- data/spec/hamster/hash/none_spec.rb +0 -64
- data/spec/hamster/hash/put_spec.rb +0 -65
- data/spec/hamster/hash/reduce_spec.rb +0 -60
- data/spec/hamster/hash/remove_spec.rb +0 -63
- data/spec/hamster/hash/slice_spec.rb +0 -31
- data/spec/hamster/hash/uniq_spec.rb +0 -23
- data/spec/hamster/hash/values_spec.rb +0 -34
- data/spec/hamster/immutable/memoize_spec.rb +0 -64
- data/spec/hamster/immutable/new_spec.rb +0 -28
- data/spec/hamster/immutable/transform_spec.rb +0 -31
- data/spec/hamster/immutable/transform_unless_spec.rb +0 -55
- data/spec/hamster/list/all_spec.rb +0 -111
- data/spec/hamster/list/any_spec.rb +0 -79
- data/spec/hamster/list/append_spec.rb +0 -50
- data/spec/hamster/list/at_spec.rb +0 -49
- data/spec/hamster/list/break_spec.rb +0 -85
- data/spec/hamster/list/cadr_spec.rb +0 -50
- data/spec/hamster/list/chunk_spec.rb +0 -40
- data/spec/hamster/list/clear_spec.rb +0 -36
- data/spec/hamster/list/combinations_spec.rb +0 -51
- data/spec/hamster/list/compact_spec.rb +0 -46
- data/spec/hamster/list/cons_spec.rb +0 -41
- data/spec/hamster/list/construction_spec.rb +0 -140
- data/spec/hamster/list/copying_spec.rb +0 -32
- data/spec/hamster/list/count_spec.rb +0 -66
- data/spec/hamster/list/coverage/assets/0.4.4/app.js +0 -66
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/blank.gif +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_close.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_loading.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_nav_left.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_nav_right.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_shadow_e.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_shadow_n.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_shadow_ne.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_shadow_nw.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_shadow_s.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_shadow_se.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_shadow_sw.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_shadow_w.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_title_left.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_title_main.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_title_over.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancy_title_right.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancybox-x.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancybox-y.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/fancybox.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/jquery.fancybox-1.3.1.css +0 -363
- data/spec/hamster/list/coverage/assets/0.4.4/fancybox/jquery.fancybox-1.3.1.pack.js +0 -44
- data/spec/hamster/list/coverage/assets/0.4.4/favicon.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/jquery-1.4.2.min.js +0 -155
- data/spec/hamster/list/coverage/assets/0.4.4/jquery.dataTables.min.js +0 -152
- data/spec/hamster/list/coverage/assets/0.4.4/jquery.timeago.js +0 -141
- data/spec/hamster/list/coverage/assets/0.4.4/jquery.url.js +0 -174
- data/spec/hamster/list/coverage/assets/0.4.4/loading.gif +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/magnify.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/spec/hamster/list/coverage/assets/0.4.4/smoothness/jquery-ui-1.8.4.custom.css +0 -295
- data/spec/hamster/list/coverage/assets/0.4.4/stylesheet.css +0 -341
- data/spec/hamster/list/coverage/covered_percent +0 -1
- data/spec/hamster/list/coverage/index.html +0 -71
- data/spec/hamster/list/coverage/resultset.yml +0 -225
- data/spec/hamster/list/cycle_spec.rb +0 -45
- data/spec/hamster/list/drop_spec.rb +0 -42
- data/spec/hamster/list/drop_while_spec.rb +0 -59
- data/spec/hamster/list/each_slice_spec.rb +0 -80
- data/spec/hamster/list/each_spec.rb +0 -72
- data/spec/hamster/list/each_with_index_spec.rb +0 -42
- data/spec/hamster/list/elem_index_spec.rb +0 -58
- data/spec/hamster/list/elem_indices_spec.rb +0 -45
- data/spec/hamster/list/empty_spec.rb +0 -47
- data/spec/hamster/list/eql_spec.rb +0 -78
- data/spec/hamster/list/filter_spec.rb +0 -61
- data/spec/hamster/list/find_indices_spec.rb +0 -45
- data/spec/hamster/list/flatten_spec.rb +0 -42
- data/spec/hamster/list/grep_spec.rb +0 -70
- data/spec/hamster/list/group_by_spec.rb +0 -77
- data/spec/hamster/list/hash_spec.rb +0 -43
- data/spec/hamster/list/init_spec.rb +0 -40
- data/spec/hamster/list/inits_spec.rb +0 -42
- data/spec/hamster/list/inspect_spec.rb +0 -43
- data/spec/hamster/list/intersperse_spec.rb +0 -40
- data/spec/hamster/list/join_spec.rb +0 -81
- data/spec/hamster/list/last_spec.rb +0 -44
- data/spec/hamster/list/map_spec.rb +0 -69
- data/spec/hamster/list/maximum_spec.rb +0 -77
- data/spec/hamster/list/minimum_spec.rb +0 -77
- data/spec/hamster/list/partition_spec.rb +0 -75
- data/spec/hamster/list/product_spec.rb +0 -44
- data/spec/hamster/list/reduce_spec.rb +0 -99
- data/spec/hamster/list/remove_spec.rb +0 -67
- data/spec/hamster/list/reverse_spec.rb +0 -52
- data/spec/hamster/list/size_spec.rb +0 -47
- data/spec/hamster/list/slice_spec.rb +0 -50
- data/spec/hamster/list/sorting_spec.rb +0 -70
- data/spec/hamster/list/span_spec.rb +0 -86
- data/spec/hamster/list/split_at_spec.rb +0 -53
- data/spec/hamster/list/sum_spec.rb +0 -44
- data/spec/hamster/list/tail_spec.rb +0 -48
- data/spec/hamster/list/tails_spec.rb +0 -42
- data/spec/hamster/list/take_spec.rb +0 -42
- data/spec/hamster/list/take_while_spec.rb +0 -62
- data/spec/hamster/list/to_a_spec.rb +0 -54
- data/spec/hamster/list/to_ary_spec.rb +0 -56
- data/spec/hamster/list/to_list_spec.rb +0 -32
- data/spec/hamster/list/to_set_spec.rb +0 -33
- data/spec/hamster/list/union_spec.rb +0 -49
- data/spec/hamster/list/uniq_spec.rb +0 -45
- data/spec/hamster/list/zip_spec.rb +0 -39
- data/spec/hamster/queue/clear_spec.rb +0 -36
- data/spec/hamster/queue/construction_spec.rb +0 -43
- data/spec/hamster/queue/dequeue_spec.rb +0 -40
- data/spec/hamster/queue/empty_spec.rb +0 -47
- data/spec/hamster/queue/enqueue_spec.rb +0 -41
- data/spec/hamster/queue/head_spec.rb +0 -35
- data/spec/hamster/queue/inspect_spec.rb +0 -31
- data/spec/hamster/queue/size_spec.rb +0 -35
- data/spec/hamster/queue/to_a_spec.rb +0 -42
- data/spec/hamster/queue/to_ary_spec.rb +0 -44
- data/spec/hamster/queue/to_list_spec.rb +0 -44
- data/spec/hamster/set/add_spec.rb +0 -51
- data/spec/hamster/set/all_spec.rb +0 -67
- data/spec/hamster/set/any_spec.rb +0 -67
- data/spec/hamster/set/clear_spec.rb +0 -36
- data/spec/hamster/set/construction_spec.rb +0 -31
- data/spec/hamster/set/copying_spec.rb +0 -23
- data/spec/hamster/set/count_spec.rb +0 -54
- data/spec/hamster/set/coverage/assets/0.4.4/app.js +0 -66
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/blank.gif +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_close.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_loading.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_nav_left.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_nav_right.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_shadow_e.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_shadow_n.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_shadow_ne.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_shadow_nw.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_shadow_s.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_shadow_se.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_shadow_sw.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_shadow_w.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_title_left.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_title_main.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_title_over.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancy_title_right.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancybox-x.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancybox-y.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/fancybox.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/jquery.fancybox-1.3.1.css +0 -363
- data/spec/hamster/set/coverage/assets/0.4.4/fancybox/jquery.fancybox-1.3.1.pack.js +0 -44
- data/spec/hamster/set/coverage/assets/0.4.4/favicon.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/jquery-1.4.2.min.js +0 -155
- data/spec/hamster/set/coverage/assets/0.4.4/jquery.dataTables.min.js +0 -152
- data/spec/hamster/set/coverage/assets/0.4.4/jquery.timeago.js +0 -141
- data/spec/hamster/set/coverage/assets/0.4.4/jquery.url.js +0 -174
- data/spec/hamster/set/coverage/assets/0.4.4/loading.gif +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/magnify.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/spec/hamster/set/coverage/assets/0.4.4/smoothness/jquery-ui-1.8.4.custom.css +0 -295
- data/spec/hamster/set/coverage/assets/0.4.4/stylesheet.css +0 -341
- data/spec/hamster/set/coverage/covered_percent +0 -1
- data/spec/hamster/set/coverage/index.html +0 -71
- data/spec/hamster/set/coverage/resultset.yml +0 -13
- data/spec/hamster/set/delete_spec.rb +0 -47
- data/spec/hamster/set/difference_spec.rb +0 -37
- data/spec/hamster/set/each_spec.rb +0 -42
- data/spec/hamster/set/empty_spec.rb +0 -35
- data/spec/hamster/set/eql_spec.rb +0 -62
- data/spec/hamster/set/exclusion_spec.rb +0 -38
- data/spec/hamster/set/filter_spec.rb +0 -79
- data/spec/hamster/set/flatten_spec.rb +0 -49
- data/spec/hamster/set/grep_spec.rb +0 -62
- data/spec/hamster/set/group_by_spec.rb +0 -65
- data/spec/hamster/set/hash_spec.rb +0 -31
- data/spec/hamster/set/head_spec.rb +0 -39
- data/spec/hamster/set/include_spec.rb +0 -35
- data/spec/hamster/set/inspect_spec.rb +0 -32
- data/spec/hamster/set/intersection_spec.rb +0 -46
- data/spec/hamster/set/map_spec.rb +0 -64
- data/spec/hamster/set/maximum_spec.rb +0 -65
- data/spec/hamster/set/minimum_spec.rb +0 -65
- data/spec/hamster/set/partition_spec.rb +0 -71
- data/spec/hamster/set/product_spec.rb +0 -32
- data/spec/hamster/set/reduce_spec.rb +0 -87
- data/spec/hamster/set/remove_spec.rb +0 -63
- data/spec/hamster/set/sorting_spec.rb +0 -58
- data/spec/hamster/set/subset_spec.rb +0 -39
- data/spec/hamster/set/superset_spec.rb +0 -39
- data/spec/hamster/set/to_a_spec.rb +0 -42
- data/spec/hamster/set/to_list_spec.rb +0 -47
- data/spec/hamster/set/to_set_spec.rb +0 -32
- data/spec/hamster/set/union_spec.rb +0 -45
- data/spec/hamster/set/uniq_spec.rb +0 -23
- data/spec/hamster/sorter/coverage/assets/0.4.4/app.js +0 -66
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/blank.gif +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_close.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_loading.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_nav_left.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_nav_right.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_shadow_e.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_shadow_n.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_shadow_ne.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_shadow_nw.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_shadow_s.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_shadow_se.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_shadow_sw.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_shadow_w.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_title_left.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_title_main.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_title_over.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancy_title_right.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancybox-x.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancybox-y.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/fancybox.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/jquery.fancybox-1.3.1.css +0 -363
- data/spec/hamster/sorter/coverage/assets/0.4.4/fancybox/jquery.fancybox-1.3.1.pack.js +0 -44
- data/spec/hamster/sorter/coverage/assets/0.4.4/favicon.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/jquery-1.4.2.min.js +0 -155
- data/spec/hamster/sorter/coverage/assets/0.4.4/jquery.dataTables.min.js +0 -152
- data/spec/hamster/sorter/coverage/assets/0.4.4/jquery.timeago.js +0 -141
- data/spec/hamster/sorter/coverage/assets/0.4.4/jquery.url.js +0 -174
- data/spec/hamster/sorter/coverage/assets/0.4.4/loading.gif +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/magnify.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/spec/hamster/sorter/coverage/assets/0.4.4/smoothness/jquery-ui-1.8.4.custom.css +0 -295
- data/spec/hamster/sorter/coverage/assets/0.4.4/stylesheet.css +0 -341
- data/spec/hamster/sorter/coverage/covered_percent +0 -1
- data/spec/hamster/sorter/coverage/index.html +0 -71
- data/spec/hamster/sorter/coverage/resultset.yml +0 -22
- data/spec/hamster/sorter/immutable_spec.rb +0 -12
- data/spec/hamster/stack/clear_spec.rb +0 -36
- data/spec/hamster/stack/construction_spec.rb +0 -43
- data/spec/hamster/stack/copying_spec.rb +0 -31
- data/spec/hamster/stack/empty_spec.rb +0 -31
- data/spec/hamster/stack/eql_spec.rb +0 -60
- data/spec/hamster/stack/immutable_spec.rb +0 -12
- data/spec/hamster/stack/inspect_spec.rb +0 -31
- data/spec/hamster/stack/peek_spec.rb +0 -40
- data/spec/hamster/stack/pop_spec.rb +0 -41
- data/spec/hamster/stack/push_spec.rb +0 -41
- data/spec/hamster/stack/size_spec.rb +0 -35
- data/spec/hamster/stack/to_a_spec.rb +0 -42
- data/spec/hamster/stack/to_ary.rb +0 -44
- data/spec/hamster/stack/to_list_spec.rb +0 -33
- data/spec/hamster/trie/remove_spec.rb +0 -117
- data/spec/hamster/tuple/copying_spec.rb +0 -24
- data/spec/hamster/tuple/eql_spec.rb +0 -61
- data/spec/hamster/tuple/first_spec.rb +0 -19
- data/spec/hamster/tuple/immutable_spec.rb +0 -12
- data/spec/hamster/tuple/inspect_spec.rb +0 -19
- data/spec/hamster/tuple/last_spec.rb +0 -19
- data/spec/hamster/tuple/to_a_spec.rb +0 -38
- data/spec/hamster/tuple/to_ary_spec.rb +0 -44
- data/spec/hamster/undefined/erase_spec.rb +0 -47
- data/spec/hamster/vector/add_spec.rb +0 -41
- data/spec/hamster/vector/any_spec.rb +0 -67
- data/spec/hamster/vector/clear_spec.rb +0 -36
- data/spec/hamster/vector/copying_spec.rb +0 -32
- data/spec/hamster/vector/each_spec.rb +0 -46
- data/spec/hamster/vector/each_with_index_spec.rb +0 -42
- data/spec/hamster/vector/empty_spec.rb +0 -35
- data/spec/hamster/vector/eql_spec.rb +0 -65
- data/spec/hamster/vector/filter_spec.rb +0 -63
- data/spec/hamster/vector/first_spec.rb +0 -35
- data/spec/hamster/vector/get_spec.rb +0 -81
- data/spec/hamster/vector/inspect_spec.rb +0 -31
- data/spec/hamster/vector/last_spec.rb +0 -32
- data/spec/hamster/vector/map_spec.rb +0 -64
- data/spec/hamster/vector/set_spec.rb +0 -153
- data/spec/hamster/vector/to_a_spec.rb +0 -42
- data/spec/hamster/vector/to_ary_spec.rb +0 -44
- data/tasks/bundler.rb +0 -2
- data/tasks/publish.rb +0 -12
- data/tasks/spec.rb +0 -13
@@ -1,34 +1,25 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require 'hamster/experimental/read_copy_update'
|
1
|
+
require "hamster/deque"
|
2
|
+
require "hamster/read_copy_update"
|
4
3
|
|
5
4
|
module Hamster
|
6
|
-
|
7
5
|
def self.mutable_queue(*items)
|
8
|
-
MutableQueue.new(
|
6
|
+
MutableQueue.new(deque(*items))
|
9
7
|
end
|
10
8
|
|
11
9
|
class MutableQueue
|
12
|
-
|
13
|
-
extend Forwardable
|
14
|
-
|
15
10
|
include ReadCopyUpdate
|
16
11
|
|
17
12
|
def enqueue(item)
|
18
13
|
transform { |queue| queue.enqueue(item) }
|
19
14
|
end
|
20
|
-
def_delegate :self, :enqueue, :<<
|
21
|
-
def_delegate :self, :enqueue, :add
|
22
15
|
|
23
16
|
def dequeue
|
24
17
|
head = nil
|
25
|
-
transform
|
18
|
+
transform do |queue|
|
26
19
|
head = queue.head
|
27
20
|
queue.dequeue
|
28
|
-
|
21
|
+
end
|
29
22
|
head
|
30
23
|
end
|
31
|
-
|
32
24
|
end
|
33
|
-
|
34
25
|
end
|
@@ -1,30 +1,25 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require 'hamster/experimental/read_copy_update'
|
1
|
+
require "hamster/set"
|
2
|
+
require "hamster/read_copy_update"
|
4
3
|
|
5
4
|
module Hamster
|
6
|
-
|
7
5
|
def self.mutable_set(*items)
|
8
6
|
MutableSet.new(set(*items))
|
9
7
|
end
|
10
8
|
|
11
9
|
class MutableSet
|
12
|
-
|
13
|
-
extend Forwardable
|
14
|
-
|
15
10
|
include ReadCopyUpdate
|
16
11
|
|
17
12
|
def add(item)
|
18
13
|
transform { |set| set.add(item) }
|
19
14
|
end
|
20
|
-
|
15
|
+
alias :<< :add
|
21
16
|
|
22
17
|
def add?(item)
|
23
18
|
added = false
|
24
|
-
transform
|
19
|
+
transform do |set|
|
25
20
|
added = !set.include?(item)
|
26
21
|
set.add(item)
|
27
|
-
|
22
|
+
end
|
28
23
|
added
|
29
24
|
end
|
30
25
|
|
@@ -34,13 +29,11 @@ module Hamster
|
|
34
29
|
|
35
30
|
def delete?(item)
|
36
31
|
deleted = false
|
37
|
-
transform
|
32
|
+
transform do |set|
|
38
33
|
deleted = set.include?(item)
|
39
34
|
set.delete(item)
|
40
|
-
|
35
|
+
end
|
41
36
|
deleted
|
42
37
|
end
|
43
|
-
|
44
38
|
end
|
45
|
-
|
46
39
|
end
|
data/lib/hamster/hash.rb
CHANGED
@@ -1,193 +1,823 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "hamster/immutable"
|
2
|
+
require "hamster/undefined"
|
3
|
+
require "hamster/enumerable"
|
4
|
+
require "hamster/trie"
|
5
|
+
require "hamster/set"
|
6
|
+
require "hamster/vector"
|
6
7
|
|
7
8
|
module Hamster
|
8
|
-
|
9
|
-
|
10
|
-
Hash.new(pairs, &block)
|
9
|
+
def self.hash(pairs = nil, &block)
|
10
|
+
(pairs.nil? && block.nil?) ? EmptyHash : Hash.new(pairs, &block)
|
11
11
|
end
|
12
12
|
|
13
|
+
# A `Hamster::Hash` maps from a set of unique keys to corresponding values,
|
14
|
+
# much like a dictionary maps from words to definitions. Given a key, it can
|
15
|
+
# efficiently store and retrieve values. Looking up a key given its value is also
|
16
|
+
# possible, but less efficient. If an existing key is stored again, the new value
|
17
|
+
# will replace that which was previously stored.
|
18
|
+
#
|
19
|
+
# It behaves much like Ruby's built-in Hash, which we will call RubyHash
|
20
|
+
# for clarity. Like RubyHash, `Hamster::Hash` uses `#hash` and `#eql?` to define
|
21
|
+
# equality between keys. Keys with the same `#hash` code, but which are not `#eql?`
|
22
|
+
# to each other, can coexist in the same `Hamster::Hash`. To retrieve a previously
|
23
|
+
# stored value, the key provided must have the same `#hash` code and be `#eql?`
|
24
|
+
# to the one used for storage.
|
25
|
+
#
|
26
|
+
# A `Hamster::Hash` can be created in several ways:
|
27
|
+
#
|
28
|
+
# Hamster.hash('Jane Doe' => 10, 'Jim Doe' => 6)
|
29
|
+
# Hamster::Hash.new(font_size: 10, font_family: 'Arial')
|
30
|
+
# Hamster::Hash[first_name: 'John', last_name: 'Smith']
|
31
|
+
#
|
32
|
+
# If you want to write your own class which inherits from `Hamster::Hash`, you can
|
33
|
+
# use either of the latter 2 forms of initialization.
|
34
|
+
#
|
35
|
+
# Note that any `Enumerable` object which yields 2-element `[key, value]` arrays
|
36
|
+
# can be used to initialize a `Hamster::Hash`. So this is also possible:
|
37
|
+
#
|
38
|
+
# Hamster::Hash.new([[:first_name, 'John'], [:last_name, 'Smith']])
|
39
|
+
#
|
40
|
+
# Like RubyHash, key/value pairs can be added using {#store}. Unlike RubyHash,
|
41
|
+
# a new hash is returned, and the existing one is left unchanged:
|
42
|
+
#
|
43
|
+
# hash = Hamster::Hash[a: 100, b: 200]
|
44
|
+
# hash.store(:c, 500) # => Hamster::Hash[:a => 100, :b => 200, :c => 500]
|
45
|
+
# hash # => Hamster::Hash[:a => 100, :b => 200]
|
46
|
+
#
|
47
|
+
# You also use {#put}. The difference is that {#put} can optionally take a block which
|
48
|
+
# is used to calculate the value to be stored:
|
49
|
+
#
|
50
|
+
# hash.put(:a) { hash[:b] + 100 } # => Hamster::Hash[:a => 300, :b => 200]
|
51
|
+
#
|
52
|
+
# Since it is immutable, all methods which you might expect to "modify" a `Hamster::Hash`
|
53
|
+
# actually return a new hash and leave the existing one unchanged. This means that the
|
54
|
+
# `hash[key] = value` syntax used with RubyHashes *cannot* be used with `Hamster::Hash`.
|
55
|
+
#
|
56
|
+
# While a `Hamster::Hash` can iterate over its keys (or values), it does not
|
57
|
+
# guarantee any specific iteration order (unlike RubyHash). Likewise, methods like
|
58
|
+
# {#flatten} do not guarantee which order the returned key/value pairs will appear
|
59
|
+
# in.
|
60
|
+
#
|
61
|
+
# Like RubyHash, a `Hamster::Hash` can have a default block which is used when
|
62
|
+
# looking up a key which does not exist in the hash. Unlike RubyHash, the default
|
63
|
+
# block will only be passed the missing key, not the hash itself:
|
64
|
+
#
|
65
|
+
# hash = Hamster::Hash.new { |n| n * 10 }
|
66
|
+
# hash[5] # => 50
|
67
|
+
#
|
68
|
+
# A default block can only be set when creating a `Hamster::Hash` with `Hamster::Hash.new` or
|
69
|
+
# {Hamster.hash Hamster.hash}, not with {Hamster::Hash.[] Hamster::Hash[]}. Default blocks
|
70
|
+
# do not survive marshalling and unmarshalling.
|
71
|
+
#
|
13
72
|
class Hash
|
14
|
-
|
15
|
-
extend Forwardable
|
16
|
-
|
17
73
|
include Immutable
|
74
|
+
include Enumerable
|
18
75
|
|
19
76
|
class << self
|
20
|
-
|
21
|
-
|
22
|
-
|
77
|
+
# Create a new `Hash` populated with the given key/value pairs.
|
78
|
+
#
|
79
|
+
# @example
|
80
|
+
# Hamster::Hash["A" => 1, "B" => 2]
|
81
|
+
# # => Hamster::Hash["A" => 1, "B" => 2]
|
82
|
+
# Hamster::Hash[["A", 1], ["B", 2]]
|
83
|
+
# # => Hamster::Hash["A" => 1, "B" => 2]
|
84
|
+
#
|
85
|
+
# @return [Hash]
|
86
|
+
def [](pairs = nil)
|
87
|
+
(pairs.nil? || pairs.empty?) ? empty : new(pairs)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Return an empty `Hash`. If used on a subclass, returns an empty instance
|
91
|
+
# of that class.
|
92
|
+
#
|
93
|
+
# @return [Hash]
|
94
|
+
def empty
|
95
|
+
@empty ||= self.new
|
23
96
|
end
|
24
97
|
|
25
|
-
|
98
|
+
# "Raw" allocation of a new `Hash`. Used internally to create a new
|
99
|
+
# instance quickly after obtaining a modified {Trie}.
|
100
|
+
#
|
101
|
+
# @return [Hash]
|
102
|
+
# @private
|
103
|
+
def alloc(trie = EmptyTrie, block = nil)
|
104
|
+
obj = allocate
|
105
|
+
obj.instance_variable_set(:@trie, trie)
|
106
|
+
obj.instance_variable_set(:@default, block)
|
107
|
+
obj
|
108
|
+
end
|
26
109
|
end
|
27
110
|
|
28
|
-
def initialize(&block)
|
29
|
-
@trie = EmptyTrie
|
111
|
+
def initialize(pairs = nil, &block)
|
112
|
+
@trie = pairs ? Trie[pairs] : EmptyTrie
|
30
113
|
@default = block
|
31
114
|
end
|
32
115
|
|
116
|
+
# Return the default block if there is one. Otherwise, return `nil`.
|
117
|
+
#
|
118
|
+
# @return [Proc]
|
119
|
+
def default_proc
|
120
|
+
@default
|
121
|
+
end
|
122
|
+
|
123
|
+
# Return the number of key/value pairs in this `Hash`.
|
124
|
+
#
|
125
|
+
# @example
|
126
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3].size # => 3
|
127
|
+
#
|
128
|
+
# @return [Integer]
|
33
129
|
def size
|
34
130
|
@trie.size
|
35
131
|
end
|
36
|
-
|
132
|
+
alias :length :size
|
37
133
|
|
134
|
+
# Return `true` if this `Hash` contains no key/value pairs.
|
135
|
+
#
|
136
|
+
# @return [Boolean]
|
38
137
|
def empty?
|
39
138
|
@trie.empty?
|
40
139
|
end
|
41
|
-
def_delegator :self, :empty?, :null?
|
42
140
|
|
43
|
-
|
44
|
-
|
141
|
+
# Return `true` if the given key object is present in this `Hash`. More precisely,
|
142
|
+
# return `true` if a key with the same `#hash` code, and which is also `#eql?`
|
143
|
+
# to the given key object is present.
|
144
|
+
#
|
145
|
+
# @example
|
146
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3].key?("B") # => true
|
147
|
+
#
|
148
|
+
# @param key [Object] The key to check for
|
149
|
+
# @return [Boolean]
|
150
|
+
def key?(key)
|
151
|
+
@trie.key?(key)
|
45
152
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
153
|
+
alias :has_key? :key?
|
154
|
+
alias :include? :key?
|
155
|
+
alias :member? :key?
|
156
|
+
|
157
|
+
# Return `true` if this `Hash` has one or more keys which map to the provided value.
|
158
|
+
#
|
159
|
+
# @example
|
160
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3].value?(2) # => true
|
161
|
+
#
|
162
|
+
# @param value [Object] The value to check for
|
163
|
+
# @return [Boolean]
|
164
|
+
def value?(value)
|
165
|
+
each { |k,v| return true if value == v }
|
166
|
+
false
|
167
|
+
end
|
168
|
+
alias :has_value? :value?
|
169
|
+
|
170
|
+
# Retrieve the value corresponding to the provided key object. If not found, and
|
171
|
+
# this `Hash` has a default block, the default block is called to provide the
|
172
|
+
# value.
|
173
|
+
#
|
174
|
+
# @example
|
175
|
+
# h = Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
176
|
+
# h["B"] # => 2
|
177
|
+
# h.get("B") # => 2
|
178
|
+
# h.get("Elephant") # => nil
|
179
|
+
#
|
180
|
+
# # Hamster Hash with a default proc:
|
181
|
+
# h = Hamster::Hash.new("A" => 1, "B" => 2, "C" => 3) { |key| key.size }
|
182
|
+
# h.get("B") # => 2
|
183
|
+
# h.get("Elephant") # => 8
|
184
|
+
#
|
185
|
+
# @param key [Object] The key to look up
|
186
|
+
# @return [Object]
|
50
187
|
def get(key)
|
51
188
|
entry = @trie.get(key)
|
52
189
|
if entry
|
53
|
-
entry
|
190
|
+
entry[1]
|
54
191
|
elsif @default
|
55
192
|
@default.call(key)
|
56
193
|
end
|
57
194
|
end
|
58
|
-
|
59
|
-
|
195
|
+
alias :[] :get
|
196
|
+
|
197
|
+
# Retrieve the value corresponding to the given key object, or use the provided
|
198
|
+
# default value or block, or otherwise raise a `KeyError`.
|
199
|
+
#
|
200
|
+
# @overload fetch(key)
|
201
|
+
# Retrieve the value corresponding to the given key, or raise a `KeyError`
|
202
|
+
# if it is not found.
|
203
|
+
# @param key [Object] The key to look up
|
204
|
+
# @overload fetch(key) { |key| ... }
|
205
|
+
# Retrieve the value corresponding to the given key, or call the optional
|
206
|
+
# code block (with the missing key) and get its return value.
|
207
|
+
# @yield [key] The key which was not found
|
208
|
+
# @yieldreturn [Object] Object to return since the key was not found
|
209
|
+
# @param key [Object] The key to look up
|
210
|
+
# @overload fetch(key, default)
|
211
|
+
# Retrieve the value corresponding to the given key, or else return
|
212
|
+
# the provided `default` value.
|
213
|
+
# @param key [Object] The key to look up
|
214
|
+
# @param default [Object] Object to return if the key is not found
|
215
|
+
#
|
216
|
+
# @example
|
217
|
+
# h = Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
218
|
+
# h.fetch("B") # => 2
|
219
|
+
# h.fetch("Elephant") # => KeyError: key not found: "Elephant"
|
220
|
+
#
|
221
|
+
# # with a default value:
|
222
|
+
# h.fetch("B", 99) # => 2
|
223
|
+
# h.fetch("Elephant", 99) # => 99
|
224
|
+
#
|
225
|
+
# # with a block:
|
226
|
+
# h.fetch("B") { |key| key.size } # => 2
|
227
|
+
# h.fetch("Elephant") { |key| key.size } # => 8
|
228
|
+
#
|
229
|
+
# @return [Object]
|
60
230
|
def fetch(key, default = Undefined)
|
61
231
|
entry = @trie.get(key)
|
62
232
|
if entry
|
63
|
-
entry
|
233
|
+
entry[1]
|
234
|
+
elsif block_given?
|
235
|
+
yield(key)
|
64
236
|
elsif default != Undefined
|
65
237
|
default
|
66
|
-
elsif block_given?
|
67
|
-
yield
|
68
238
|
else
|
69
|
-
raise KeyError
|
239
|
+
raise KeyError, "key not found: #{key.inspect}"
|
70
240
|
end
|
71
241
|
end
|
72
242
|
|
73
|
-
|
74
|
-
|
75
|
-
|
243
|
+
# Return a new `Hash` with the existing key/value associations, plus an association
|
244
|
+
# between the provided key and value. If an equivalent key is already present, its
|
245
|
+
# associated value will be replaced with the provided one.
|
246
|
+
#
|
247
|
+
# If the `value` argument is missing, but an optional code block is provided,
|
248
|
+
# it will be passed the existing value (or `nil` if there is none) and what it
|
249
|
+
# returns will replace the existing value. This is useful for "transforming"
|
250
|
+
# the value associated with a certain key.
|
251
|
+
#
|
252
|
+
# Avoid mutating objects which are used as keys. `String`s are an exception --
|
253
|
+
# unfrozen `String`s which are used as keys are internally duplicated and
|
254
|
+
# frozen.
|
255
|
+
#
|
256
|
+
# @example
|
257
|
+
# h = Hamster::Hash["A" => 1, "B" => 2]
|
258
|
+
# h.put("C", 3)
|
259
|
+
# # => Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
260
|
+
# h.put("B") { |value| value * 10 }
|
261
|
+
# # => Hamster::Hash["A" => 1, "B" => 20]
|
262
|
+
#
|
263
|
+
# @param key [Object] The key to store
|
264
|
+
# @param value [Object] The value to associate it with
|
265
|
+
# @yield [value] The previously stored value
|
266
|
+
# @yieldreturn [Object] The new value to store
|
267
|
+
# @return [Hash]
|
268
|
+
def put(key, value = yield(get(key)))
|
269
|
+
new_trie = @trie.put(key, value)
|
270
|
+
if new_trie.equal?(@trie)
|
271
|
+
self
|
272
|
+
else
|
273
|
+
self.class.alloc(new_trie, @default)
|
274
|
+
end
|
76
275
|
end
|
77
276
|
|
78
|
-
|
79
|
-
|
80
|
-
|
277
|
+
# Return a new `Hash` with a deeply nested value modified to the result of
|
278
|
+
# the given code block. When traversing the nested `Hash`es and `Vector`s,
|
279
|
+
# non-existing keys are created with empty `Hash` values.
|
280
|
+
#
|
281
|
+
# The code block receives the existing value of the deeply nested key (or
|
282
|
+
# `nil` if it doesn't exist). This is useful for "transforming" the value
|
283
|
+
# associated with a certain key.
|
284
|
+
#
|
285
|
+
# Note that the original `Hash` and sub-`Hash`es and sub-`Vector`s are left
|
286
|
+
# unmodified; new data structure copies are created along the path wherever
|
287
|
+
# needed.
|
288
|
+
#
|
289
|
+
# @example
|
290
|
+
# hash = Hamster::Hash["a" => Hamster::Hash["b" => Hamster::Hash["c" => 42]]]
|
291
|
+
# hash.update_in("a", "b", "c") { |value| value + 5 }
|
292
|
+
# # => Hamster::Hash["a" => Hamster::Hash["b" => Hamster::Hash["c" => 47]]]
|
293
|
+
#
|
294
|
+
# @param key_path [Object(s)] List of keys which form the path to the key to be modified
|
295
|
+
# @yield [value] The previously stored value
|
296
|
+
# @yieldreturn [Object] The new value to store
|
297
|
+
# @return [Hash]
|
298
|
+
def update_in(*key_path, &block)
|
299
|
+
if key_path.empty?
|
300
|
+
raise ArgumentError, "must have at least one key in path"
|
301
|
+
end
|
302
|
+
key = key_path[0]
|
303
|
+
if key_path.size == 1
|
304
|
+
new_value = block.call(get(key))
|
305
|
+
else
|
306
|
+
value = fetch(key, EmptyHash)
|
307
|
+
new_value = value.update_in(*key_path[1..-1], &block)
|
308
|
+
end
|
309
|
+
put(key, new_value)
|
81
310
|
end
|
82
311
|
|
83
|
-
|
84
|
-
|
85
|
-
|
312
|
+
# Return a new `Hash` with the existing key/value associations, plus an association
|
313
|
+
# between the provided key and value. If an equivalent key is already present, its
|
314
|
+
# associated value will be replaced with the provided one.
|
315
|
+
#
|
316
|
+
# Avoid mutating objects which are used as keys. `String`s are an exception --
|
317
|
+
# unfrozen `String`s which are used as keys are internally duplicated and
|
318
|
+
# frozen.
|
319
|
+
#
|
320
|
+
# @example
|
321
|
+
# Hamster::Hash["A" => 1, "B" => 2].store("C", 3)
|
322
|
+
# # => Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
323
|
+
#
|
324
|
+
# @param key [Object] The key to store
|
325
|
+
# @param value [Object] The value to associate it with
|
326
|
+
# @return [Hash]
|
327
|
+
def store(key, value)
|
328
|
+
put(key, value)
|
86
329
|
end
|
87
|
-
def_delegator :self, :each, :foreach
|
88
330
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
331
|
+
# Return a new `Hash` with the association for `key` removed. If `key` is not
|
332
|
+
# present, return `self`.
|
333
|
+
#
|
334
|
+
# @example
|
335
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3].delete("B")
|
336
|
+
# # => Hamster::Hash["A" => 1, "C" => 3]
|
337
|
+
#
|
338
|
+
# @param key [Object] The key to remove
|
339
|
+
# @return [Hash]
|
340
|
+
def delete(key)
|
341
|
+
derive_new_hash(@trie.delete(key))
|
93
342
|
end
|
94
|
-
def_delegator :self, :map, :collect
|
95
343
|
|
96
|
-
|
97
|
-
|
98
|
-
|
344
|
+
# Call the block once for each key/value pair in this `Hash`, passing the key/value
|
345
|
+
# pair as parameters. No specific iteration order is guaranteed (but the order will
|
346
|
+
# be stable for any particular `Hash`.)
|
347
|
+
#
|
348
|
+
# @example
|
349
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3].each { |k, v| puts "k=#{k} v=#{v}" }
|
350
|
+
#
|
351
|
+
# k=A v=1
|
352
|
+
# k=B v=2
|
353
|
+
# k=C v=3
|
354
|
+
# # => Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
355
|
+
#
|
356
|
+
# @return [self]
|
357
|
+
def each(&block)
|
358
|
+
return to_enum if not block_given?
|
359
|
+
@trie.each(&block)
|
360
|
+
self
|
99
361
|
end
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
362
|
+
alias :each_pair :each
|
363
|
+
|
364
|
+
# Call the block once for each key/value pair in this `Hash`, passing the key/value
|
365
|
+
# pair as parameters. Iteration order will be the opposite of {#each}.
|
366
|
+
#
|
367
|
+
# @example
|
368
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3].reverse_each { |k, v| puts "k=#{k} v=#{v}" }
|
369
|
+
#
|
370
|
+
# k=C v=3
|
371
|
+
# k=B v=2
|
372
|
+
# k=A v=1
|
373
|
+
# # => Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
374
|
+
#
|
375
|
+
# @return [self]
|
376
|
+
def reverse_each(&block)
|
377
|
+
return enum_for(:reverse_each) if not block_given?
|
378
|
+
@trie.reverse_each(&block)
|
379
|
+
self
|
109
380
|
end
|
110
|
-
def_delegator :self, :filter, :select
|
111
|
-
def_delegator :self, :filter, :find_all
|
112
381
|
|
113
|
-
|
114
|
-
|
115
|
-
|
382
|
+
# Call the block once for each key/value pair in this `Hash`, passing the key as a
|
383
|
+
# parameter.
|
384
|
+
#
|
385
|
+
# @example
|
386
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3].each_key { |k| puts "k=#{k}" }
|
387
|
+
#
|
388
|
+
# k=A
|
389
|
+
# k=B
|
390
|
+
# k=C
|
391
|
+
# # => Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
392
|
+
#
|
393
|
+
# @return [self]
|
394
|
+
def each_key
|
395
|
+
return enum_for(:each_key) if not block_given?
|
396
|
+
@trie.each { |k,v| yield k }
|
397
|
+
self
|
116
398
|
end
|
117
|
-
def_delegator :self, :remove, :reject
|
118
|
-
def_delegator :self, :remove, :delete_if
|
119
399
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
400
|
+
# Call the block once for each key/value pair in this `Hash`, passing the value as a
|
401
|
+
# parameter.
|
402
|
+
#
|
403
|
+
# @example
|
404
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3].each_value { |v| puts "v=#{v}" }
|
405
|
+
#
|
406
|
+
# v=1
|
407
|
+
# v=2
|
408
|
+
# v=3
|
409
|
+
# # => Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
410
|
+
#
|
411
|
+
# @return [self]
|
412
|
+
def each_value
|
413
|
+
return enum_for(:each_value) if not block_given?
|
414
|
+
@trie.each { |k,v| yield v }
|
415
|
+
self
|
124
416
|
end
|
125
|
-
def_delegator :self, :any?, :exist?
|
126
|
-
def_delegator :self, :any?, :exists?
|
127
417
|
|
128
|
-
|
129
|
-
|
130
|
-
|
418
|
+
# Call the block once for each key/value pair in this `Hash`, passing the key/value
|
419
|
+
# pair as parameters. The block should return a `[key, value]` array each time.
|
420
|
+
# All the returned `[key, value]` arrays will be gathered into a new `Hash`.
|
421
|
+
#
|
422
|
+
# @example
|
423
|
+
# h = Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
424
|
+
# h.map { |k, v| ["new-#{k}", v * v] }
|
425
|
+
# # => Hash["new-C" => 9, "new-B" => 4, "new-A" => 1]
|
426
|
+
#
|
427
|
+
# @return [Hash]
|
428
|
+
def map
|
429
|
+
return enum_for(:map) unless block_given?
|
430
|
+
return self if empty?
|
431
|
+
self.class.new(super, &@default)
|
131
432
|
end
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
433
|
+
alias :collect :map
|
434
|
+
|
435
|
+
# Return a new `Hash` with all the key/value pairs for which the block returns true.
|
436
|
+
#
|
437
|
+
# @example
|
438
|
+
# h = Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
439
|
+
# h.select { |k, v| v >= 2 }
|
440
|
+
# # => Hamster::Hash["B" => 2, "C" => 3]
|
441
|
+
#
|
442
|
+
# @return [Hash]
|
443
|
+
def select(&block)
|
444
|
+
return enum_for(:select) unless block_given?
|
445
|
+
derive_new_hash(@trie.select(&block))
|
138
446
|
end
|
139
|
-
|
447
|
+
alias :find_all :select
|
448
|
+
alias :keep_if :select
|
449
|
+
|
450
|
+
# Yield `[key, value]` pairs until one is found for which the block returns true.
|
451
|
+
# Return that `[key, value]` pair. If the block never returns true, return `nil`.
|
452
|
+
#
|
453
|
+
# @example
|
454
|
+
# h = Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
455
|
+
# h.find { |k, v| v.even? }
|
456
|
+
# # => ["B", 2]
|
457
|
+
#
|
458
|
+
# @return [Array]
|
140
459
|
def find
|
141
|
-
return
|
142
|
-
each { |
|
460
|
+
return enum_for(:find) unless block_given?
|
461
|
+
each { |entry| return entry if yield entry }
|
143
462
|
nil
|
144
463
|
end
|
145
|
-
|
146
|
-
|
464
|
+
alias :detect :find
|
465
|
+
|
466
|
+
# Return a new `Hash` containing all the key/value pairs from this `Hash` and
|
467
|
+
# `other`. If no block is provided, the value for entries with colliding keys
|
468
|
+
# will be that from `other`. Otherwie, the value for each duplicate key is
|
469
|
+
# determined by called the block with the key, its value in this `Hash`, and
|
470
|
+
# its value in `other`.
|
471
|
+
#
|
472
|
+
# `other` can be a `Hamster::Hash`, a built-in Ruby `Hash`, or any `Enumerable`
|
473
|
+
# object which yields `[key, value]` pairs.
|
474
|
+
#
|
475
|
+
# @example
|
476
|
+
# h1 = Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
477
|
+
# h2 = Hamster::Hash["C" => 70, "D" => 80]
|
478
|
+
# h1.merge(h2)
|
479
|
+
# # => Hamster::Hash["C" => 70, "A" => 1, "D" => 80, "B" => 2]
|
480
|
+
# h1.merge(h2) { |key, v1, v2| v1 + v2 }
|
481
|
+
# # => Hamster::Hash["C" => 73, "A" => 1, "D" => 80, "B" => 2]
|
482
|
+
#
|
483
|
+
# @param other [Enumerable] The collection to merge with
|
484
|
+
# @yieldparam key [Object] The key which was present in both collections
|
485
|
+
# @yieldparam my_value [Object] The associated value from this `Hash`
|
486
|
+
# @yieldparam other_value [Object] The associated value from the other collection
|
487
|
+
# @yieldreturn [Object] The value to associate this key with in the new `Hash`
|
488
|
+
# @return [Hash]
|
147
489
|
def merge(other)
|
148
|
-
|
490
|
+
trie = if block_given?
|
491
|
+
other.reduce(@trie) do |trie, (key, value)|
|
492
|
+
if entry = trie.get(key)
|
493
|
+
trie.put(key, yield(key, entry[1], value))
|
494
|
+
else
|
495
|
+
trie.put(key, value)
|
496
|
+
end
|
497
|
+
end
|
498
|
+
else
|
499
|
+
@trie.bulk_put(other)
|
500
|
+
end
|
501
|
+
|
502
|
+
derive_new_hash(trie)
|
503
|
+
end
|
504
|
+
|
505
|
+
# Return a {Vector} which contains all the `[key, value]` pairs in this `Hash`
|
506
|
+
# as 2-element Arrays, either in their natural sorted order as determined by
|
507
|
+
# `#<=>`, or if an optional block is supplied, by using the block as a comparator.
|
508
|
+
# See `Enumerable#sort`.
|
509
|
+
#
|
510
|
+
# @example
|
511
|
+
# h = Hamster::Hash["Dog" => 1, "Elephant" => 2, "Lion" => 3]
|
512
|
+
# h.sort { |(k1, v1), (k2, v2)| k1.size <=> k2.size }
|
513
|
+
# # => Hamster::Vector[["Dog", 1], ["Lion", 3], ["Elephant", 2]]
|
514
|
+
#
|
515
|
+
# @return [Vector]
|
516
|
+
def sort
|
517
|
+
Vector.new(super)
|
518
|
+
end
|
519
|
+
|
520
|
+
# Return a {Vector} which contains all the `[key, value]` pairs in this `Hash`
|
521
|
+
# as 2-element Arrays. The order which the pairs will appear in is determined by
|
522
|
+
# passing each pair to the code block to obtain a sort key object, and comparing
|
523
|
+
# the sort keys using `#<=>`.
|
524
|
+
# See `Enumerable#sort_by`.
|
525
|
+
#
|
526
|
+
# @example
|
527
|
+
# h = Hamster::Hash["Dog" => 1, "Elephant" => 2, "Lion" => 3]
|
528
|
+
# h.sort_by { |key, value| key.size }
|
529
|
+
# # => Hamster::Vector[["Dog", 1], ["Lion", 3], ["Elephant", 2]]
|
530
|
+
#
|
531
|
+
# @return [Vector]
|
532
|
+
def sort_by
|
533
|
+
Vector.new(super)
|
149
534
|
end
|
150
|
-
def_delegator :self, :merge, :+
|
151
535
|
|
536
|
+
# Return a new `Hash` with the associations for all of the given `keys` removed.
|
537
|
+
#
|
538
|
+
# @example
|
539
|
+
# h = Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
540
|
+
# h.except("A", "C") # => Hamster::Hash["B" => 2]
|
541
|
+
#
|
542
|
+
# @param keys [Array] The keys to remove
|
543
|
+
# @return [Hash]
|
152
544
|
def except(*keys)
|
153
545
|
keys.reduce(self) { |hash, key| hash.delete(key) }
|
154
546
|
end
|
155
547
|
|
156
|
-
|
157
|
-
|
548
|
+
# Return a new `Hash` with only the associations for the `wanted` keys retained.
|
549
|
+
# If any of the `wanted` keys are not present in this `Hash`, they will not be present
|
550
|
+
# in the returned `Hash` either.
|
551
|
+
#
|
552
|
+
# @example
|
553
|
+
# h = Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
554
|
+
# h.slice("B", "C") # => Hamster::Hash["B" => 2, "C" => 3]
|
555
|
+
#
|
556
|
+
# @param wanted [Array] The keys to retain
|
557
|
+
# @return [Hash]
|
558
|
+
def slice(*wanted)
|
559
|
+
trie = Trie.new(0)
|
560
|
+
wanted.each { |key| trie.put!(key, get(key)) if key?(key) }
|
561
|
+
self.class.alloc(trie, @default)
|
158
562
|
end
|
159
563
|
|
564
|
+
# Return a {Vector} of the values which correspond to the `wanted` keys.
|
565
|
+
# If any of the `wanted` keys are not present in this `Hash`, they will be skipped.
|
566
|
+
#
|
567
|
+
# @example
|
568
|
+
# h = Hamster::Hash["A" => 1, "B" => 2, "C" => 3]
|
569
|
+
# h.values_at("B", "A") # => Hamster::Vector[2, 1]
|
570
|
+
#
|
571
|
+
# @param wanted [Array] The keys to retrieve
|
572
|
+
# @return [Vector]
|
573
|
+
def values_at(*wanted)
|
574
|
+
array = []
|
575
|
+
wanted.each { |key| array << get(key) if key?(key) }
|
576
|
+
Vector.new(array.freeze)
|
577
|
+
end
|
578
|
+
|
579
|
+
# Return a new {Set} populated with the keys from this `Hash`.
|
580
|
+
#
|
581
|
+
# @example
|
582
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3, "D" => 2].keys
|
583
|
+
# # => Hamster::Set["D", "C", "B", "A"]
|
584
|
+
#
|
585
|
+
# @return [Set]
|
160
586
|
def keys
|
161
|
-
|
587
|
+
Set.alloc(@trie)
|
162
588
|
end
|
163
589
|
|
590
|
+
# Return a new {Vector} populated with the values from this `Hash`.
|
591
|
+
#
|
592
|
+
# @example
|
593
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3, "D" => 2].values
|
594
|
+
# # => Hamster::Vector[2, 3, 2, 1]
|
595
|
+
#
|
596
|
+
# @return [Vector]
|
164
597
|
def values
|
165
|
-
|
598
|
+
Vector.new(each_value.to_a.freeze)
|
599
|
+
end
|
600
|
+
|
601
|
+
# Return a new `Hash` created by using our keys as values, and values as keys.
|
602
|
+
# If there are multiple values which are equivalent (as determined by `#hash` and
|
603
|
+
# `#eql?`), only one out of each group of equivalent values will be retained.
|
604
|
+
#
|
605
|
+
# @example
|
606
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3, "D" => 2].invert
|
607
|
+
# # => Hamster::Hash[1 => "A", 3 => "C", 2 => "B"]
|
608
|
+
#
|
609
|
+
# @return [Hash]
|
610
|
+
def invert
|
611
|
+
pairs = []
|
612
|
+
each { |k,v| pairs << [v, k] }
|
613
|
+
self.class.new(pairs, &@default)
|
614
|
+
end
|
615
|
+
|
616
|
+
# Return a new {Vector} which is a one-dimensional flattening of this `Hash`.
|
617
|
+
# If `level` is 1, all the `[key, value]` pairs in the hash will be concatenated
|
618
|
+
# into one {Vector}. If `level` is greater than 1, keys or values which are
|
619
|
+
# themselves `Array`s or {Vector}s will be recursively flattened into the output
|
620
|
+
# {Vector}. The depth to which that flattening will be recursively applied is
|
621
|
+
# determined by `level`.
|
622
|
+
#
|
623
|
+
# As a special case, if `level` is 0, each `[key, value]` pair will be a
|
624
|
+
# separate element in the returned {Vector}.
|
625
|
+
#
|
626
|
+
# @example
|
627
|
+
# h = Hamster::Hash["A" => 1, "B" => [2, 3, 4]]
|
628
|
+
# h.flatten
|
629
|
+
# # => Hamster::Vector["A", 1, "B", [2, 3, 4]]
|
630
|
+
# h.flatten(2)
|
631
|
+
# # => Hamster::Vector["A", 1, "B", 2, 3, 4]
|
632
|
+
#
|
633
|
+
# @param level [Integer] The number of times to recursively flatten the `[key, value]` pairs in this `Hash`.
|
634
|
+
# @return [Vector]
|
635
|
+
def flatten(level = 1)
|
636
|
+
return Vector.new(self) if level == 0
|
637
|
+
array = []
|
638
|
+
each { |k,v| array << k; array << v }
|
639
|
+
array.flatten!(level-1) if level > 1
|
640
|
+
Vector.new(array.freeze)
|
166
641
|
end
|
167
642
|
|
643
|
+
# Searches through the `Hash`, comparing `obj` with each key (using `#==`).
|
644
|
+
# When a matching key is found, return the `[key, value]` pair as an array.
|
645
|
+
# Return `nil` if no match is found.
|
646
|
+
#
|
647
|
+
# @example
|
648
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3].assoc("B") # => ["B", 2]
|
649
|
+
#
|
650
|
+
# @param obj [Object] The key to search for (using #==)
|
651
|
+
# @return [Array]
|
652
|
+
def assoc(obj)
|
653
|
+
each { |entry| return entry if obj == entry[0] }
|
654
|
+
nil
|
655
|
+
end
|
656
|
+
|
657
|
+
# Searches through the `Hash`, comparing `obj` with each value (using `#==`).
|
658
|
+
# When a matching value is found, return the `[key, value]` pair as an array.
|
659
|
+
# Return `nil` if no match is found.
|
660
|
+
#
|
661
|
+
# @example
|
662
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3].rassoc(2) # => ["B", 2]
|
663
|
+
#
|
664
|
+
# @param obj [Object] The value to search for (using #==)
|
665
|
+
# @return [Array]
|
666
|
+
def rassoc(obj)
|
667
|
+
each { |entry| return entry if obj == entry[1] }
|
668
|
+
nil
|
669
|
+
end
|
670
|
+
|
671
|
+
# Searches through the `Hash`, comparing `value` with each value (using `#==`).
|
672
|
+
# When a matching value is found, return its associated key object.
|
673
|
+
# Return `nil` if no match is found.
|
674
|
+
#
|
675
|
+
# @example
|
676
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3].key(2) # => "B"
|
677
|
+
#
|
678
|
+
# @param value [Object] The value to search for (using #==)
|
679
|
+
# @return [Object]
|
680
|
+
def key(value)
|
681
|
+
each { |entry| return entry[0] if value == entry[1] }
|
682
|
+
nil
|
683
|
+
end
|
684
|
+
|
685
|
+
# Return a randomly chosen `[key, value]` pair from this `Hash`. If the hash is empty,
|
686
|
+
# return `nil`.
|
687
|
+
#
|
688
|
+
# @example
|
689
|
+
# Hamster::Hash["A" => 1, "B" => 2, "C" => 3].sample
|
690
|
+
# # => ["C", 3]
|
691
|
+
#
|
692
|
+
# @return [Array]
|
693
|
+
def sample
|
694
|
+
@trie.at(rand(size))
|
695
|
+
end
|
696
|
+
|
697
|
+
# Return an empty `Hash` instance, of the same class as this one. Useful if you
|
698
|
+
# have multiple subclasses of `Hash` and want to treat them polymorphically.
|
699
|
+
# Maintains the default block, if there is one.
|
700
|
+
#
|
701
|
+
# @return [Hash]
|
168
702
|
def clear
|
169
|
-
|
703
|
+
if @default
|
704
|
+
self.class.alloc(EmptyTrie, @default)
|
705
|
+
else
|
706
|
+
self.class.empty
|
707
|
+
end
|
170
708
|
end
|
171
709
|
|
710
|
+
# Return true if `other` has the same type and contents as this `Hash`.
|
711
|
+
#
|
712
|
+
# @param other [Object] The collection to compare with
|
713
|
+
# @return [Boolean]
|
172
714
|
def eql?(other)
|
715
|
+
return true if other.equal?(self)
|
173
716
|
instance_of?(other.class) && @trie.eql?(other.instance_variable_get(:@trie))
|
174
717
|
end
|
175
|
-
def_delegator :self, :eql?, :==
|
176
718
|
|
177
|
-
|
178
|
-
|
719
|
+
# Return true if `other` has the same contents as this `Hash`. Will convert
|
720
|
+
# `other` to a Ruby `Hash` using `#to_hash` if necessary.
|
721
|
+
#
|
722
|
+
# @param other [Object] The object to compare with
|
723
|
+
# @return [Boolean]
|
724
|
+
def ==(other)
|
725
|
+
self.eql?(other) || (other.respond_to?(:to_hash) && to_hash.eql?(other.to_hash))
|
179
726
|
end
|
180
727
|
|
181
|
-
|
182
|
-
|
183
|
-
|
728
|
+
# See `Object#hash`.
|
729
|
+
# @return [Integer]
|
730
|
+
def hash
|
731
|
+
keys.to_a.sort.reduce(0) do |hash, key|
|
732
|
+
(hash << 32) - hash + key.hash + get(key).hash
|
733
|
+
end
|
734
|
+
end
|
184
735
|
|
736
|
+
# Return the contents of this `Hash` as a programmer-readable `String`. If all the
|
737
|
+
# keys and values are serializable as Ruby literal strings, the returned string can
|
738
|
+
# be passed to `eval` to reconstitute an equivalent `Hash`. However, the default
|
739
|
+
# block (if there is one) will be lost when doing this.
|
740
|
+
#
|
741
|
+
# @return [String]
|
185
742
|
def inspect
|
186
|
-
|
743
|
+
result = "#{self.class}["
|
744
|
+
i = 0
|
745
|
+
each do |key, val|
|
746
|
+
result << ', ' if i > 0
|
747
|
+
result << key.inspect << ' => ' << val.inspect
|
748
|
+
i += 1
|
749
|
+
end
|
750
|
+
result << "]"
|
187
751
|
end
|
188
752
|
|
189
|
-
|
753
|
+
# Allows this `Hash` to be printed at the `pry` console, or using `pp` (from the
|
754
|
+
# Ruby standard library), in a way which takes the amount of horizontal space on
|
755
|
+
# the screen into account, and which indents nested structures to make them easier
|
756
|
+
# to read.
|
757
|
+
#
|
758
|
+
# @private
|
759
|
+
def pretty_print(pp)
|
760
|
+
pp.group(1, "#{self.class}[", "]") do
|
761
|
+
pp.breakable ''
|
762
|
+
pp.seplist(self, nil) do |key, val|
|
763
|
+
pp.group do
|
764
|
+
key.pretty_print(pp)
|
765
|
+
pp.text ' => '
|
766
|
+
pp.group(1) do
|
767
|
+
pp.breakable ''
|
768
|
+
val.pretty_print(pp)
|
769
|
+
end
|
770
|
+
end
|
771
|
+
end
|
772
|
+
end
|
773
|
+
end
|
190
774
|
|
191
|
-
|
775
|
+
# Convert this `Hamster::Hash` to an instance of Ruby's built-in `Hash`.
|
776
|
+
#
|
777
|
+
# @return [::Hash]
|
778
|
+
def to_hash
|
779
|
+
output = {}
|
780
|
+
each do |key, value|
|
781
|
+
output[key] = value
|
782
|
+
end
|
783
|
+
output
|
784
|
+
end
|
785
|
+
alias :to_h :to_hash
|
786
|
+
|
787
|
+
# @return [::Hash]
|
788
|
+
# @private
|
789
|
+
def marshal_dump
|
790
|
+
to_hash
|
791
|
+
end
|
792
|
+
|
793
|
+
# @private
|
794
|
+
def marshal_load(dictionary)
|
795
|
+
@trie = Trie[dictionary]
|
796
|
+
end
|
797
|
+
|
798
|
+
private
|
799
|
+
|
800
|
+
# Return a new `Hash` which is derived from this one, using a modified {Trie}.
|
801
|
+
# The new `Hash` will retain the existing default block, if there is one.
|
802
|
+
#
|
803
|
+
def derive_new_hash(trie)
|
804
|
+
if trie.equal?(@trie)
|
805
|
+
self
|
806
|
+
elsif trie.empty?
|
807
|
+
if @default
|
808
|
+
self.class.alloc(EmptyTrie, @default)
|
809
|
+
else
|
810
|
+
self.class.empty
|
811
|
+
end
|
812
|
+
else
|
813
|
+
self.class.alloc(trie, @default)
|
814
|
+
end
|
815
|
+
end
|
816
|
+
end
|
192
817
|
|
818
|
+
# The canonical empty `Hash`. Returned by `Hamster.hash` and `Hash[]` when
|
819
|
+
# invoked with no arguments; also returned by `Hash.empty`. Prefer using this
|
820
|
+
# one rather than creating many empty hashes using `Hash.new`.
|
821
|
+
#
|
822
|
+
EmptyHash = Hamster::Hash.empty
|
193
823
|
end
|