immutable-ruby 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/immutable/core_ext/enumerable.rb +1 -1
- data/lib/immutable/core_ext/io.rb +1 -1
- data/lib/immutable/core_ext.rb +2 -2
- data/lib/immutable/deque.rb +50 -15
- data/lib/immutable/enumerable.rb +19 -10
- data/lib/immutable/hash.rb +128 -28
- data/lib/immutable/list.rb +48 -48
- data/lib/immutable/nested.rb +10 -7
- data/lib/immutable/set.rb +30 -30
- data/lib/immutable/sorted_set.rb +77 -37
- data/lib/immutable/trie.rb +21 -29
- data/lib/immutable/vector.rb +61 -46
- data/lib/immutable/version.rb +1 -1
- data/lib/immutable.rb +9 -9
- metadata +44 -687
- data/spec/fixtures/io_spec.txt +0 -3
- data/spec/lib/immutable/core_ext/array_spec.rb +0 -13
- data/spec/lib/immutable/core_ext/enumerable_spec.rb +0 -29
- data/spec/lib/immutable/core_ext/io_spec.rb +0 -28
- data/spec/lib/immutable/deque/clear_spec.rb +0 -33
- data/spec/lib/immutable/deque/construction_spec.rb +0 -29
- data/spec/lib/immutable/deque/copying_spec.rb +0 -19
- data/spec/lib/immutable/deque/dequeue_spec.rb +0 -34
- data/spec/lib/immutable/deque/empty_spec.rb +0 -39
- data/spec/lib/immutable/deque/enqueue_spec.rb +0 -27
- data/spec/lib/immutable/deque/first_spec.rb +0 -17
- data/spec/lib/immutable/deque/inspect_spec.rb +0 -23
- data/spec/lib/immutable/deque/last_spec.rb +0 -17
- data/spec/lib/immutable/deque/marshal_spec.rb +0 -33
- data/spec/lib/immutable/deque/new_spec.rb +0 -43
- data/spec/lib/immutable/deque/pop_spec.rb +0 -36
- data/spec/lib/immutable/deque/pretty_print_spec.rb +0 -23
- data/spec/lib/immutable/deque/push_spec.rb +0 -36
- data/spec/lib/immutable/deque/random_modification_spec.rb +0 -33
- data/spec/lib/immutable/deque/shift_spec.rb +0 -29
- data/spec/lib/immutable/deque/size_spec.rb +0 -19
- data/spec/lib/immutable/deque/to_a_spec.rb +0 -26
- data/spec/lib/immutable/deque/to_ary_spec.rb +0 -35
- data/spec/lib/immutable/deque/to_list_spec.rb +0 -24
- data/spec/lib/immutable/deque/unshift_spec.rb +0 -30
- data/spec/lib/immutable/hash/all_spec.rb +0 -53
- data/spec/lib/immutable/hash/any_spec.rb +0 -53
- data/spec/lib/immutable/hash/assoc_spec.rb +0 -51
- data/spec/lib/immutable/hash/clear_spec.rb +0 -42
- data/spec/lib/immutable/hash/construction_spec.rb +0 -38
- data/spec/lib/immutable/hash/copying_spec.rb +0 -13
- data/spec/lib/immutable/hash/default_proc_spec.rb +0 -72
- data/spec/lib/immutable/hash/delete_spec.rb +0 -39
- data/spec/lib/immutable/hash/each_spec.rb +0 -77
- data/spec/lib/immutable/hash/each_with_index_spec.rb +0 -29
- data/spec/lib/immutable/hash/empty_spec.rb +0 -43
- data/spec/lib/immutable/hash/eql_spec.rb +0 -69
- data/spec/lib/immutable/hash/except_spec.rb +0 -42
- data/spec/lib/immutable/hash/fetch_spec.rb +0 -57
- data/spec/lib/immutable/hash/find_spec.rb +0 -43
- data/spec/lib/immutable/hash/flat_map_spec.rb +0 -35
- data/spec/lib/immutable/hash/flatten_spec.rb +0 -98
- data/spec/lib/immutable/hash/get_spec.rb +0 -79
- data/spec/lib/immutable/hash/has_key_spec.rb +0 -31
- data/spec/lib/immutable/hash/has_value_spec.rb +0 -27
- data/spec/lib/immutable/hash/hash_spec.rb +0 -29
- data/spec/lib/immutable/hash/inspect_spec.rb +0 -30
- data/spec/lib/immutable/hash/invert_spec.rb +0 -30
- data/spec/lib/immutable/hash/key_spec.rb +0 -27
- data/spec/lib/immutable/hash/keys_spec.rb +0 -15
- data/spec/lib/immutable/hash/map_spec.rb +0 -45
- data/spec/lib/immutable/hash/marshal_spec.rb +0 -28
- data/spec/lib/immutable/hash/merge_spec.rb +0 -82
- data/spec/lib/immutable/hash/min_max_spec.rb +0 -45
- data/spec/lib/immutable/hash/new_spec.rb +0 -70
- data/spec/lib/immutable/hash/none_spec.rb +0 -48
- data/spec/lib/immutable/hash/partition_spec.rb +0 -35
- data/spec/lib/immutable/hash/pretty_print_spec.rb +0 -34
- data/spec/lib/immutable/hash/put_spec.rb +0 -102
- data/spec/lib/immutable/hash/reduce_spec.rb +0 -35
- data/spec/lib/immutable/hash/reject_spec.rb +0 -61
- data/spec/lib/immutable/hash/reverse_each_spec.rb +0 -27
- data/spec/lib/immutable/hash/sample_spec.rb +0 -13
- data/spec/lib/immutable/hash/select_spec.rb +0 -57
- data/spec/lib/immutable/hash/size_spec.rb +0 -51
- data/spec/lib/immutable/hash/slice_spec.rb +0 -44
- data/spec/lib/immutable/hash/sort_spec.rb +0 -26
- data/spec/lib/immutable/hash/store_spec.rb +0 -75
- data/spec/lib/immutable/hash/take_spec.rb +0 -35
- data/spec/lib/immutable/hash/to_a_spec.rb +0 -13
- data/spec/lib/immutable/hash/to_hash_spec.rb +0 -21
- data/spec/lib/immutable/hash/update_in_spec.rb +0 -79
- data/spec/lib/immutable/hash/values_at_spec.rb +0 -13
- data/spec/lib/immutable/hash/values_spec.rb +0 -23
- data/spec/lib/immutable/list/add_spec.rb +0 -25
- data/spec/lib/immutable/list/all_spec.rb +0 -57
- data/spec/lib/immutable/list/any_spec.rb +0 -49
- data/spec/lib/immutable/list/append_spec.rb +0 -38
- data/spec/lib/immutable/list/at_spec.rb +0 -29
- data/spec/lib/immutable/list/break_spec.rb +0 -69
- data/spec/lib/immutable/list/cadr_spec.rb +0 -38
- data/spec/lib/immutable/list/chunk_spec.rb +0 -28
- data/spec/lib/immutable/list/clear_spec.rb +0 -24
- data/spec/lib/immutable/list/combination_spec.rb +0 -33
- data/spec/lib/immutable/list/compact_spec.rb +0 -34
- data/spec/lib/immutable/list/compare_spec.rb +0 -30
- data/spec/lib/immutable/list/cons_spec.rb +0 -25
- data/spec/lib/immutable/list/construction_spec.rb +0 -110
- data/spec/lib/immutable/list/copying_spec.rb +0 -19
- data/spec/lib/immutable/list/count_spec.rb +0 -36
- data/spec/lib/immutable/list/cycle_spec.rb +0 -28
- data/spec/lib/immutable/list/delete_at_spec.rb +0 -18
- data/spec/lib/immutable/list/delete_spec.rb +0 -16
- data/spec/lib/immutable/list/drop_spec.rb +0 -30
- data/spec/lib/immutable/list/drop_while_spec.rb +0 -38
- data/spec/lib/immutable/list/each_slice_spec.rb +0 -51
- data/spec/lib/immutable/list/each_spec.rb +0 -40
- data/spec/lib/immutable/list/each_with_index_spec.rb +0 -28
- data/spec/lib/immutable/list/empty_spec.rb +0 -23
- data/spec/lib/immutable/list/eql_spec.rb +0 -61
- data/spec/lib/immutable/list/fill_spec.rb +0 -49
- data/spec/lib/immutable/list/find_all_spec.rb +0 -70
- data/spec/lib/immutable/list/find_index_spec.rb +0 -35
- data/spec/lib/immutable/list/find_spec.rb +0 -42
- data/spec/lib/immutable/list/flat_map_spec.rb +0 -51
- data/spec/lib/immutable/list/flatten_spec.rb +0 -30
- data/spec/lib/immutable/list/grep_spec.rb +0 -46
- data/spec/lib/immutable/list/group_by_spec.rb +0 -41
- data/spec/lib/immutable/list/hash_spec.rb +0 -21
- data/spec/lib/immutable/list/head_spec.rb +0 -19
- data/spec/lib/immutable/list/include_spec.rb +0 -35
- data/spec/lib/immutable/list/index_spec.rb +0 -33
- data/spec/lib/immutable/list/indices_spec.rb +0 -61
- data/spec/lib/immutable/list/init_spec.rb +0 -28
- data/spec/lib/immutable/list/inits_spec.rb +0 -28
- data/spec/lib/immutable/list/insert_spec.rb +0 -46
- data/spec/lib/immutable/list/inspect_spec.rb +0 -29
- data/spec/lib/immutable/list/intersperse_spec.rb +0 -28
- data/spec/lib/immutable/list/join_spec.rb +0 -63
- data/spec/lib/immutable/list/last_spec.rb +0 -23
- data/spec/lib/immutable/list/ltlt_spec.rb +0 -19
- data/spec/lib/immutable/list/map_spec.rb +0 -45
- data/spec/lib/immutable/list/maximum_spec.rb +0 -39
- data/spec/lib/immutable/list/merge_by_spec.rb +0 -51
- data/spec/lib/immutable/list/merge_spec.rb +0 -59
- data/spec/lib/immutable/list/minimum_spec.rb +0 -39
- data/spec/lib/immutable/list/multithreading_spec.rb +0 -47
- data/spec/lib/immutable/list/none_spec.rb +0 -47
- data/spec/lib/immutable/list/one_spec.rb +0 -49
- data/spec/lib/immutable/list/partition_spec.rb +0 -115
- data/spec/lib/immutable/list/permutation_spec.rb +0 -55
- data/spec/lib/immutable/list/pop_spec.rb +0 -25
- data/spec/lib/immutable/list/product_spec.rb +0 -23
- data/spec/lib/immutable/list/reduce_spec.rb +0 -53
- data/spec/lib/immutable/list/reject_spec.rb +0 -45
- data/spec/lib/immutable/list/reverse_spec.rb +0 -34
- data/spec/lib/immutable/list/rotate_spec.rb +0 -36
- data/spec/lib/immutable/list/sample_spec.rb +0 -13
- data/spec/lib/immutable/list/select_spec.rb +0 -70
- data/spec/lib/immutable/list/size_spec.rb +0 -25
- data/spec/lib/immutable/list/slice_spec.rb +0 -229
- data/spec/lib/immutable/list/sorting_spec.rb +0 -46
- data/spec/lib/immutable/list/span_spec.rb +0 -76
- data/spec/lib/immutable/list/split_at_spec.rb +0 -43
- data/spec/lib/immutable/list/subsequences_spec.rb +0 -23
- data/spec/lib/immutable/list/sum_spec.rb +0 -23
- data/spec/lib/immutable/list/tail_spec.rb +0 -30
- data/spec/lib/immutable/list/tails_spec.rb +0 -28
- data/spec/lib/immutable/list/take_spec.rb +0 -30
- data/spec/lib/immutable/list/take_while_spec.rb +0 -46
- data/spec/lib/immutable/list/to_a_spec.rb +0 -39
- data/spec/lib/immutable/list/to_ary_spec.rb +0 -41
- data/spec/lib/immutable/list/to_list_spec.rb +0 -19
- data/spec/lib/immutable/list/to_set_spec.rb +0 -17
- data/spec/lib/immutable/list/transpose_spec.rb +0 -19
- data/spec/lib/immutable/list/union_spec.rb +0 -31
- data/spec/lib/immutable/list/uniq_spec.rb +0 -35
- data/spec/lib/immutable/list/zip_spec.rb +0 -23
- data/spec/lib/immutable/nested/construction_spec.rb +0 -95
- data/spec/lib/immutable/set/add_spec.rb +0 -75
- data/spec/lib/immutable/set/all_spec.rb +0 -51
- data/spec/lib/immutable/set/any_spec.rb +0 -51
- data/spec/lib/immutable/set/clear_spec.rb +0 -33
- data/spec/lib/immutable/set/compact_spec.rb +0 -30
- data/spec/lib/immutable/set/construction_spec.rb +0 -18
- data/spec/lib/immutable/set/copying_spec.rb +0 -13
- data/spec/lib/immutable/set/count_spec.rb +0 -36
- data/spec/lib/immutable/set/delete_spec.rb +0 -71
- data/spec/lib/immutable/set/difference_spec.rb +0 -49
- data/spec/lib/immutable/set/disjoint_spec.rb +0 -25
- data/spec/lib/immutable/set/each_spec.rb +0 -45
- data/spec/lib/immutable/set/empty_spec.rb +0 -44
- data/spec/lib/immutable/set/eqeq_spec.rb +0 -103
- data/spec/lib/immutable/set/eql_spec.rb +0 -109
- data/spec/lib/immutable/set/exclusion_spec.rb +0 -47
- data/spec/lib/immutable/set/find_spec.rb +0 -35
- data/spec/lib/immutable/set/first_spec.rb +0 -28
- data/spec/lib/immutable/set/flatten_spec.rb +0 -46
- data/spec/lib/immutable/set/grep_spec.rb +0 -57
- data/spec/lib/immutable/set/group_by_spec.rb +0 -59
- data/spec/lib/immutable/set/hash_spec.rb +0 -22
- data/spec/lib/immutable/set/include_spec.rb +0 -60
- data/spec/lib/immutable/set/inspect_spec.rb +0 -47
- data/spec/lib/immutable/set/intersect_spec.rb +0 -25
- data/spec/lib/immutable/set/intersection_spec.rb +0 -52
- data/spec/lib/immutable/set/join_spec.rb +0 -64
- data/spec/lib/immutable/set/map_spec.rb +0 -59
- data/spec/lib/immutable/set/marshal_spec.rb +0 -28
- data/spec/lib/immutable/set/maximum_spec.rb +0 -36
- data/spec/lib/immutable/set/minimum_spec.rb +0 -36
- data/spec/lib/immutable/set/new_spec.rb +0 -53
- data/spec/lib/immutable/set/none_spec.rb +0 -47
- data/spec/lib/immutable/set/one_spec.rb +0 -47
- data/spec/lib/immutable/set/partition_spec.rb +0 -52
- data/spec/lib/immutable/set/product_spec.rb +0 -23
- data/spec/lib/immutable/set/reduce_spec.rb +0 -55
- data/spec/lib/immutable/set/reject_spec.rb +0 -50
- data/spec/lib/immutable/set/reverse_each_spec.rb +0 -38
- data/spec/lib/immutable/set/sample_spec.rb +0 -13
- data/spec/lib/immutable/set/select_spec.rb +0 -73
- data/spec/lib/immutable/set/size_spec.rb +0 -17
- data/spec/lib/immutable/set/sorting_spec.rb +0 -59
- data/spec/lib/immutable/set/subset_spec.rb +0 -51
- data/spec/lib/immutable/set/sum_spec.rb +0 -23
- data/spec/lib/immutable/set/superset_spec.rb +0 -51
- data/spec/lib/immutable/set/to_a_spec.rb +0 -30
- data/spec/lib/immutable/set/to_list_spec.rb +0 -35
- data/spec/lib/immutable/set/to_set_spec.rb +0 -19
- data/spec/lib/immutable/set/union_spec.rb +0 -63
- data/spec/lib/immutable/sorted_set/above_spec.rb +0 -51
- data/spec/lib/immutable/sorted_set/add_spec.rb +0 -62
- data/spec/lib/immutable/sorted_set/at_spec.rb +0 -24
- data/spec/lib/immutable/sorted_set/below_spec.rb +0 -51
- data/spec/lib/immutable/sorted_set/between_spec.rb +0 -51
- data/spec/lib/immutable/sorted_set/clear_spec.rb +0 -43
- data/spec/lib/immutable/sorted_set/copying_spec.rb +0 -20
- data/spec/lib/immutable/sorted_set/delete_at_spec.rb +0 -18
- data/spec/lib/immutable/sorted_set/delete_spec.rb +0 -89
- data/spec/lib/immutable/sorted_set/difference_spec.rb +0 -22
- data/spec/lib/immutable/sorted_set/disjoint_spec.rb +0 -25
- data/spec/lib/immutable/sorted_set/drop_spec.rb +0 -55
- data/spec/lib/immutable/sorted_set/drop_while_spec.rb +0 -34
- data/spec/lib/immutable/sorted_set/each_spec.rb +0 -28
- data/spec/lib/immutable/sorted_set/empty_spec.rb +0 -34
- data/spec/lib/immutable/sorted_set/eql_spec.rb +0 -120
- data/spec/lib/immutable/sorted_set/exclusion_spec.rb +0 -22
- data/spec/lib/immutable/sorted_set/fetch_spec.rb +0 -64
- data/spec/lib/immutable/sorted_set/find_index_spec.rb +0 -40
- data/spec/lib/immutable/sorted_set/first_spec.rb +0 -18
- data/spec/lib/immutable/sorted_set/from_spec.rb +0 -51
- data/spec/lib/immutable/sorted_set/group_by_spec.rb +0 -57
- data/spec/lib/immutable/sorted_set/include_spec.rb +0 -23
- data/spec/lib/immutable/sorted_set/inspect_spec.rb +0 -37
- data/spec/lib/immutable/sorted_set/intersect_spec.rb +0 -25
- data/spec/lib/immutable/sorted_set/intersection_spec.rb +0 -28
- data/spec/lib/immutable/sorted_set/last_spec.rb +0 -36
- data/spec/lib/immutable/sorted_set/map_spec.rb +0 -43
- data/spec/lib/immutable/sorted_set/marshal_spec.rb +0 -36
- data/spec/lib/immutable/sorted_set/maximum_spec.rb +0 -36
- data/spec/lib/immutable/sorted_set/minimum_spec.rb +0 -19
- data/spec/lib/immutable/sorted_set/new_spec.rb +0 -71
- data/spec/lib/immutable/sorted_set/reverse_each_spec.rb +0 -28
- data/spec/lib/immutable/sorted_set/sample_spec.rb +0 -13
- data/spec/lib/immutable/sorted_set/select_spec.rb +0 -61
- data/spec/lib/immutable/sorted_set/size_spec.rb +0 -17
- data/spec/lib/immutable/sorted_set/slice_spec.rb +0 -256
- data/spec/lib/immutable/sorted_set/sorting_spec.rb +0 -44
- data/spec/lib/immutable/sorted_set/subset_spec.rb +0 -47
- data/spec/lib/immutable/sorted_set/superset_spec.rb +0 -47
- data/spec/lib/immutable/sorted_set/take_spec.rb +0 -54
- data/spec/lib/immutable/sorted_set/take_while_spec.rb +0 -33
- data/spec/lib/immutable/sorted_set/to_set_spec.rb +0 -17
- data/spec/lib/immutable/sorted_set/union_spec.rb +0 -27
- data/spec/lib/immutable/sorted_set/up_to_spec.rb +0 -52
- data/spec/lib/immutable/sorted_set/values_at_spec.rb +0 -33
- data/spec/lib/immutable/vector/add_spec.rb +0 -67
- data/spec/lib/immutable/vector/any_spec.rb +0 -69
- data/spec/lib/immutable/vector/assoc_spec.rb +0 -45
- data/spec/lib/immutable/vector/bsearch_spec.rb +0 -65
- data/spec/lib/immutable/vector/clear_spec.rb +0 -33
- data/spec/lib/immutable/vector/combination_spec.rb +0 -81
- data/spec/lib/immutable/vector/compact_spec.rb +0 -29
- data/spec/lib/immutable/vector/compare_spec.rb +0 -31
- data/spec/lib/immutable/vector/concat_spec.rb +0 -34
- data/spec/lib/immutable/vector/copying_spec.rb +0 -20
- data/spec/lib/immutable/vector/count_spec.rb +0 -17
- data/spec/lib/immutable/vector/delete_at_spec.rb +0 -53
- data/spec/lib/immutable/vector/delete_spec.rb +0 -30
- data/spec/lib/immutable/vector/drop_spec.rb +0 -41
- data/spec/lib/immutable/vector/drop_while_spec.rb +0 -54
- data/spec/lib/immutable/vector/each_index_spec.rb +0 -40
- data/spec/lib/immutable/vector/each_spec.rb +0 -44
- data/spec/lib/immutable/vector/each_with_index_spec.rb +0 -39
- data/spec/lib/immutable/vector/empty_spec.rb +0 -41
- data/spec/lib/immutable/vector/eql_spec.rb +0 -76
- data/spec/lib/immutable/vector/fetch_spec.rb +0 -64
- data/spec/lib/immutable/vector/fill_spec.rb +0 -88
- data/spec/lib/immutable/vector/first_spec.rb +0 -18
- data/spec/lib/immutable/vector/flat_map_spec.rb +0 -50
- data/spec/lib/immutable/vector/flatten_spec.rb +0 -58
- data/spec/lib/immutable/vector/get_spec.rb +0 -74
- data/spec/lib/immutable/vector/group_by_spec.rb +0 -57
- data/spec/lib/immutable/vector/include_spec.rb +0 -30
- data/spec/lib/immutable/vector/insert_spec.rb +0 -68
- data/spec/lib/immutable/vector/inspect_spec.rb +0 -49
- data/spec/lib/immutable/vector/join_spec.rb +0 -58
- data/spec/lib/immutable/vector/last_spec.rb +0 -45
- data/spec/lib/immutable/vector/length_spec.rb +0 -45
- data/spec/lib/immutable/vector/ltlt_spec.rb +0 -65
- data/spec/lib/immutable/vector/map_spec.rb +0 -51
- data/spec/lib/immutable/vector/marshal_spec.rb +0 -31
- data/spec/lib/immutable/vector/maximum_spec.rb +0 -33
- data/spec/lib/immutable/vector/minimum_spec.rb +0 -33
- data/spec/lib/immutable/vector/multiply_spec.rb +0 -47
- data/spec/lib/immutable/vector/new_spec.rb +0 -50
- data/spec/lib/immutable/vector/partition_spec.rb +0 -52
- data/spec/lib/immutable/vector/permutation_spec.rb +0 -91
- data/spec/lib/immutable/vector/pop_spec.rb +0 -26
- data/spec/lib/immutable/vector/product_spec.rb +0 -70
- data/spec/lib/immutable/vector/reduce_spec.rb +0 -55
- data/spec/lib/immutable/vector/reject_spec.rb +0 -43
- data/spec/lib/immutable/vector/repeated_combination_spec.rb +0 -77
- data/spec/lib/immutable/vector/repeated_permutation_spec.rb +0 -93
- data/spec/lib/immutable/vector/reverse_each_spec.rb +0 -31
- data/spec/lib/immutable/vector/reverse_spec.rb +0 -21
- data/spec/lib/immutable/vector/rindex_spec.rb +0 -36
- data/spec/lib/immutable/vector/rotate_spec.rb +0 -73
- data/spec/lib/immutable/vector/sample_spec.rb +0 -13
- data/spec/lib/immutable/vector/select_spec.rb +0 -63
- data/spec/lib/immutable/vector/set_spec.rb +0 -174
- data/spec/lib/immutable/vector/shift_spec.rb +0 -27
- data/spec/lib/immutable/vector/shuffle_spec.rb +0 -43
- data/spec/lib/immutable/vector/slice_spec.rb +0 -240
- data/spec/lib/immutable/vector/sorting_spec.rb +0 -56
- data/spec/lib/immutable/vector/sum_spec.rb +0 -17
- data/spec/lib/immutable/vector/take_spec.rb +0 -42
- data/spec/lib/immutable/vector/take_while_spec.rb +0 -34
- data/spec/lib/immutable/vector/to_a_spec.rb +0 -41
- data/spec/lib/immutable/vector/to_ary_spec.rb +0 -34
- data/spec/lib/immutable/vector/to_list_spec.rb +0 -30
- data/spec/lib/immutable/vector/to_set_spec.rb +0 -21
- data/spec/lib/immutable/vector/transpose_spec.rb +0 -48
- data/spec/lib/immutable/vector/uniq_spec.rb +0 -76
- data/spec/lib/immutable/vector/unshift_spec.rb +0 -28
- data/spec/lib/immutable/vector/update_in_spec.rb +0 -82
- data/spec/lib/immutable/vector/values_at_spec.rb +0 -33
- data/spec/lib/immutable/vector/zip_spec.rb +0 -57
- data/spec/lib/load_spec.rb +0 -42
- data/spec/spec_helper.rb +0 -92
data/lib/immutable/sorted_set.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'immutable/enumerable'
|
2
2
|
|
3
3
|
module Immutable
|
4
4
|
|
@@ -65,7 +65,7 @@ module Immutable
|
|
65
65
|
#
|
66
66
|
# @return [SortedSet]
|
67
67
|
def empty
|
68
|
-
@empty ||=
|
68
|
+
@empty ||= alloc(PlainAVLNode::EmptyNode)
|
69
69
|
end
|
70
70
|
|
71
71
|
# "Raw" allocation of a new `SortedSet`. Used internally to create a new
|
@@ -76,21 +76,46 @@ module Immutable
|
|
76
76
|
def alloc(node)
|
77
77
|
allocate.tap { |s| s.instance_variable_set(:@node, node) }.freeze
|
78
78
|
end
|
79
|
+
|
80
|
+
# @private
|
81
|
+
# Unfortunately, Ruby's stdlib doesn't do this for us
|
82
|
+
# array must be sorted
|
83
|
+
def uniq_by_comparator!(array, comparator)
|
84
|
+
to_check, shift, sz, prev_obj = 1, 0, array.size, array[0]
|
85
|
+
while to_check < sz
|
86
|
+
next_obj = array[to_check]
|
87
|
+
if comparator.call(prev_obj, next_obj) == 0
|
88
|
+
shift += 1
|
89
|
+
else
|
90
|
+
if shift > 0
|
91
|
+
array[to_check - shift] = next_obj
|
92
|
+
end
|
93
|
+
prev_obj = next_obj
|
94
|
+
end
|
95
|
+
to_check += 1
|
96
|
+
end
|
97
|
+
array.pop(shift) if shift > 0
|
98
|
+
end
|
79
99
|
end
|
80
100
|
|
81
101
|
def initialize(items=[], &block)
|
82
102
|
items = items.to_a
|
83
103
|
if block
|
84
|
-
|
104
|
+
# In Ruby 2, &:method blocks have arity -1; in Ruby 3, it's -2
|
105
|
+
if block.arity == 1 || block.arity == -1 || block.arity == -2
|
106
|
+
items = items.uniq(&block)
|
107
|
+
items.sort_by!(&block)
|
85
108
|
comparator = lambda { |a,b| block.call(a) <=> block.call(b) }
|
86
|
-
|
87
|
-
else
|
88
|
-
comparator = block
|
109
|
+
elsif block.arity == 2 || block.arity == -3
|
89
110
|
items = items.sort(&block)
|
111
|
+
SortedSet.uniq_by_comparator!(items, block)
|
112
|
+
comparator = block
|
113
|
+
else
|
114
|
+
raise "Comparator block for Immutable::SortedSet must accept 1 or 2 arguments"
|
90
115
|
end
|
91
116
|
@node = AVLNode.from_items(items, comparator)
|
92
117
|
else
|
93
|
-
@node = PlainAVLNode.from_items(items.sort)
|
118
|
+
@node = PlainAVLNode.from_items(items.uniq.sort!)
|
94
119
|
end
|
95
120
|
freeze
|
96
121
|
end
|
@@ -111,7 +136,7 @@ module Immutable
|
|
111
136
|
def size
|
112
137
|
@node.size
|
113
138
|
end
|
114
|
-
alias
|
139
|
+
alias length size
|
115
140
|
|
116
141
|
# Return a new `SortedSet` with `item` added. If `item` is already in the set,
|
117
142
|
# return `self`.
|
@@ -129,7 +154,7 @@ module Immutable
|
|
129
154
|
end
|
130
155
|
self
|
131
156
|
end
|
132
|
-
alias
|
157
|
+
alias << add
|
133
158
|
|
134
159
|
# If `item` is not a member of this `SortedSet`, return a new `SortedSet` with
|
135
160
|
# `item` added. Otherwise, return `false`.
|
@@ -321,7 +346,7 @@ module Immutable
|
|
321
346
|
subsequence(arg, length)
|
322
347
|
end
|
323
348
|
end
|
324
|
-
alias
|
349
|
+
alias [] slice
|
325
350
|
|
326
351
|
# Return a new `SortedSet` with only the elements at the given `indices`.
|
327
352
|
# If any of the `indices` do not exist, they will be skipped.
|
@@ -429,8 +454,8 @@ module Immutable
|
|
429
454
|
each { |item| items_to_delete << item unless yield(item) }
|
430
455
|
derive_new_sorted_set(@node.bulk_delete(items_to_delete))
|
431
456
|
end
|
432
|
-
alias
|
433
|
-
alias
|
457
|
+
alias find_all select
|
458
|
+
alias keep_if select
|
434
459
|
|
435
460
|
# Invoke the given block once for each item in the set, and return a new
|
436
461
|
# `SortedSet` containing the values returned by the block. If no block is
|
@@ -447,7 +472,7 @@ module Immutable
|
|
447
472
|
return self if empty?
|
448
473
|
self.class.alloc(@node.from_items(super))
|
449
474
|
end
|
450
|
-
alias
|
475
|
+
alias collect map
|
451
476
|
|
452
477
|
# Return `true` if the given item is present in this `SortedSet`. More precisely,
|
453
478
|
# return `true` if an object which compares as "equal" using this set's
|
@@ -461,7 +486,7 @@ module Immutable
|
|
461
486
|
def include?(item)
|
462
487
|
@node.include?(item)
|
463
488
|
end
|
464
|
-
alias
|
489
|
+
alias member? include?
|
465
490
|
|
466
491
|
# Return a new `SortedSet` with the same items, but a sort order determined
|
467
492
|
# by the given block.
|
@@ -475,12 +500,14 @@ module Immutable
|
|
475
500
|
# @return [SortedSet]
|
476
501
|
def sort(&block)
|
477
502
|
if block
|
478
|
-
self.class.new(
|
503
|
+
self.class.new(to_a, &block)
|
504
|
+
elsif @node.natural_order?
|
505
|
+
self
|
479
506
|
else
|
480
|
-
self.class.new(self
|
481
|
-
end
|
507
|
+
self.class.new(self)
|
508
|
+
end
|
482
509
|
end
|
483
|
-
alias
|
510
|
+
alias sort_by sort
|
484
511
|
|
485
512
|
# Find the index of a given object or an element that satisfies the given
|
486
513
|
# block.
|
@@ -526,7 +553,7 @@ module Immutable
|
|
526
553
|
super(&block)
|
527
554
|
end
|
528
555
|
end
|
529
|
-
alias
|
556
|
+
alias index find_index
|
530
557
|
|
531
558
|
# Drop the first `n` elements and return the rest in a new `SortedSet`.
|
532
559
|
#
|
@@ -604,9 +631,9 @@ module Immutable
|
|
604
631
|
def union(other)
|
605
632
|
self.class.alloc(@node.bulk_insert(other))
|
606
633
|
end
|
607
|
-
alias
|
608
|
-
alias
|
609
|
-
alias
|
634
|
+
alias | union
|
635
|
+
alias + union
|
636
|
+
alias merge union
|
610
637
|
|
611
638
|
# Return a new `SortedSet` which contains all the items which are members of both
|
612
639
|
# this set and `other`. `other` can be any `Enumerable` object.
|
@@ -620,7 +647,7 @@ module Immutable
|
|
620
647
|
def intersection(other)
|
621
648
|
self.class.alloc(@node.keep_only(other))
|
622
649
|
end
|
623
|
-
alias
|
650
|
+
alias & intersection
|
624
651
|
|
625
652
|
# Return a new `SortedSet` with all the items in `other` removed. `other` can be
|
626
653
|
# any `Enumerable` object.
|
@@ -634,8 +661,8 @@ module Immutable
|
|
634
661
|
def difference(other)
|
635
662
|
self.class.alloc(@node.bulk_delete(other))
|
636
663
|
end
|
637
|
-
alias
|
638
|
-
alias
|
664
|
+
alias subtract difference
|
665
|
+
alias - difference
|
639
666
|
|
640
667
|
# Return a new `SortedSet` with all the items which are members of this
|
641
668
|
# set or of `other`, but not both. `other` can be any `Enumerable` object.
|
@@ -649,7 +676,7 @@ module Immutable
|
|
649
676
|
def exclusion(other)
|
650
677
|
((self | other) - (self & other))
|
651
678
|
end
|
652
|
-
alias
|
679
|
+
alias ^ exclusion
|
653
680
|
|
654
681
|
# Return `true` if all items in this set are also in `other`.
|
655
682
|
#
|
@@ -728,8 +755,8 @@ module Immutable
|
|
728
755
|
!disjoint?(other)
|
729
756
|
end
|
730
757
|
|
731
|
-
alias
|
732
|
-
alias
|
758
|
+
alias group group_by
|
759
|
+
alias classify group_by
|
733
760
|
|
734
761
|
# Select elements greater than a value.
|
735
762
|
#
|
@@ -923,10 +950,11 @@ module Immutable
|
|
923
950
|
return true if other.equal?(self)
|
924
951
|
return false if not instance_of?(other.class)
|
925
952
|
return false if size != other.size
|
926
|
-
a, b =
|
927
|
-
|
953
|
+
a, b = to_enum, other.to_enum
|
954
|
+
loop do
|
928
955
|
return false if !a.next.eql?(b.next)
|
929
956
|
end
|
957
|
+
true
|
930
958
|
rescue StopIteration
|
931
959
|
true
|
932
960
|
end
|
@@ -943,7 +971,7 @@ module Immutable
|
|
943
971
|
def dup
|
944
972
|
self
|
945
973
|
end
|
946
|
-
alias
|
974
|
+
alias clone dup
|
947
975
|
|
948
976
|
# @return [::Array]
|
949
977
|
# @private
|
@@ -990,7 +1018,8 @@ module Immutable
|
|
990
1018
|
|
991
1019
|
# @private
|
992
1020
|
class AVLNode
|
993
|
-
def self.from_items(items, comparator, from = 0, to = items.size-1)
|
1021
|
+
def self.from_items(items, comparator, from = 0, to = items.size-1)
|
1022
|
+
# items must be sorted, without duplicates (as determined by comparator)
|
994
1023
|
size = to - from + 1
|
995
1024
|
if size >= 3
|
996
1025
|
middle = (to + from) / 2
|
@@ -1013,8 +1042,12 @@ module Immutable
|
|
1013
1042
|
end
|
1014
1043
|
attr_reader :item, :left, :right, :height, :size
|
1015
1044
|
|
1045
|
+
# Used to implement #map
|
1046
|
+
# Takes advantage of the fact that Enumerable#map allocates a new Array
|
1016
1047
|
def from_items(items)
|
1017
|
-
|
1048
|
+
items.sort!(&@comparator)
|
1049
|
+
SortedSet.uniq_by_comparator!(items, @comparator)
|
1050
|
+
AVLNode.from_items(items, @comparator)
|
1018
1051
|
end
|
1019
1052
|
|
1020
1053
|
def natural_order?
|
@@ -1374,7 +1407,9 @@ module Immutable
|
|
1374
1407
|
end
|
1375
1408
|
def bulk_insert(items)
|
1376
1409
|
items = items.to_a if !items.is_a?(Array)
|
1377
|
-
|
1410
|
+
items = items.sort(&@comparator)
|
1411
|
+
SortedSet.uniq_by_comparator!(items, @comparator)
|
1412
|
+
AVLNode.from_items(items, @comparator)
|
1378
1413
|
end
|
1379
1414
|
def bulk_delete(items); self; end
|
1380
1415
|
def keep_only(items); self; end
|
@@ -1397,7 +1432,8 @@ module Immutable
|
|
1397
1432
|
# AVL node which does not use a comparator function; it keeps items sorted
|
1398
1433
|
# in their natural order
|
1399
1434
|
class PlainAVLNode < AVLNode
|
1400
|
-
def self.from_items(items, from = 0, to = items.size-1)
|
1435
|
+
def self.from_items(items, from = 0, to = items.size-1)
|
1436
|
+
# items must be sorted, with no duplicates
|
1401
1437
|
size = to - from + 1
|
1402
1438
|
if size >= 3
|
1403
1439
|
middle = (to + from) / 2
|
@@ -1418,8 +1454,12 @@ module Immutable
|
|
1418
1454
|
end
|
1419
1455
|
attr_reader :item, :left, :right, :height, :size
|
1420
1456
|
|
1457
|
+
# Used to implement #map
|
1458
|
+
# Takes advantage of the fact that Enumerable#map allocates a new Array
|
1421
1459
|
def from_items(items)
|
1422
|
-
|
1460
|
+
items.uniq!
|
1461
|
+
items.sort!
|
1462
|
+
PlainAVLNode.from_items(items)
|
1423
1463
|
end
|
1424
1464
|
|
1425
1465
|
def natural_order?
|
@@ -1447,7 +1487,7 @@ module Immutable
|
|
1447
1487
|
end
|
1448
1488
|
def bulk_insert(items)
|
1449
1489
|
items = items.to_a if !items.is_a?(Array)
|
1450
|
-
PlainAVLNode.from_items(items.sort)
|
1490
|
+
PlainAVLNode.from_items(items.uniq.sort!)
|
1451
1491
|
end
|
1452
1492
|
end
|
1453
1493
|
|
data/lib/immutable/trie.rb
CHANGED
@@ -2,7 +2,7 @@ module Immutable
|
|
2
2
|
# @private
|
3
3
|
class Trie
|
4
4
|
def self.[](pairs)
|
5
|
-
result =
|
5
|
+
result = new(0)
|
6
6
|
pairs.each { |key, val| result.put!(key, val) }
|
7
7
|
result
|
8
8
|
end
|
@@ -10,8 +10,8 @@ module Immutable
|
|
10
10
|
# Returns the number of key-value pairs in the trie.
|
11
11
|
attr_reader :size
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@
|
13
|
+
def initialize(bitshift, size = 0, entries = [], children = [])
|
14
|
+
@bitshift = bitshift
|
15
15
|
@entries = entries
|
16
16
|
@children = children
|
17
17
|
@size = size
|
@@ -19,7 +19,7 @@ module Immutable
|
|
19
19
|
|
20
20
|
# Returns <tt>true</tt> if the trie contains no key-value pairs.
|
21
21
|
def empty?
|
22
|
-
size == 0
|
22
|
+
@size == 0
|
23
23
|
end
|
24
24
|
|
25
25
|
# Returns <tt>true</tt> if the given key is present in the trie.
|
@@ -29,15 +29,7 @@ module Immutable
|
|
29
29
|
|
30
30
|
# Calls <tt>block</tt> once for each entry in the trie, passing the key-value pair as parameters.
|
31
31
|
def each(&block)
|
32
|
-
|
33
|
-
# the latter segfaults on ruby 2.2 and above. Once that is fixed and
|
34
|
-
# broken versions are sufficiently old, we should revert back to yield
|
35
|
-
# with a warning that the broken versions are unsupported.
|
36
|
-
#
|
37
|
-
# For more context:
|
38
|
-
# * https://bugs.ruby-lang.org/issues/11451
|
39
|
-
# * https://github.com/hamstergem/hamster/issues/189
|
40
|
-
@entries.each { |entry| block.call(entry) if entry }
|
32
|
+
@entries.each { |entry| yield entry if entry }
|
41
33
|
@children.each do |child|
|
42
34
|
child.each(&block) if child
|
43
35
|
end
|
@@ -65,7 +57,7 @@ module Immutable
|
|
65
57
|
|
66
58
|
# @return [Trie] A copy of `self` with the given value associated with the
|
67
59
|
# key (or `self` if no modification was needed because an identical
|
68
|
-
# key-value pair
|
60
|
+
# key-value pair was already stored
|
69
61
|
def put(key, value)
|
70
62
|
index = index_for(key)
|
71
63
|
entry = @entries[index]
|
@@ -74,7 +66,7 @@ module Immutable
|
|
74
66
|
entries = @entries.dup
|
75
67
|
key = key.dup.freeze if key.is_a?(String) && !key.frozen?
|
76
68
|
entries[index] = [key, value].freeze
|
77
|
-
Trie.new(@
|
69
|
+
Trie.new(@bitshift, @size + 1, entries, @children)
|
78
70
|
elsif entry[0].eql?(key)
|
79
71
|
if entry[1].equal?(value)
|
80
72
|
self
|
@@ -82,7 +74,7 @@ module Immutable
|
|
82
74
|
entries = @entries.dup
|
83
75
|
key = key.dup.freeze if key.is_a?(String) && !key.frozen?
|
84
76
|
entries[index] = [key, value].freeze
|
85
|
-
Trie.new(@
|
77
|
+
Trie.new(@bitshift, @size, entries, @children)
|
86
78
|
end
|
87
79
|
else
|
88
80
|
child = @children[index]
|
@@ -94,12 +86,12 @@ module Immutable
|
|
94
86
|
children = @children.dup
|
95
87
|
children[index] = new_child
|
96
88
|
new_self_size = @size + (new_child.size - child.size)
|
97
|
-
Trie.new(@
|
89
|
+
Trie.new(@bitshift, new_self_size, @entries, children)
|
98
90
|
end
|
99
91
|
else
|
100
92
|
children = @children.dup
|
101
|
-
children[index] = Trie.new(@
|
102
|
-
Trie.new(@
|
93
|
+
children[index] = Trie.new(@bitshift + 5).put!(key, value)
|
94
|
+
Trie.new(@bitshift, @size + 1, @entries, children)
|
103
95
|
end
|
104
96
|
end
|
105
97
|
end
|
@@ -141,14 +133,14 @@ module Immutable
|
|
141
133
|
end
|
142
134
|
else
|
143
135
|
new_children ||= @children.dup
|
144
|
-
new_children[index] = Trie.new(@
|
136
|
+
new_children[index] = Trie.new(@bitshift + 5).put!(key, value)
|
145
137
|
new_size += 1
|
146
138
|
end
|
147
139
|
end
|
148
140
|
end
|
149
141
|
|
150
142
|
if new_entries || new_children
|
151
|
-
Trie.new(@
|
143
|
+
Trie.new(@bitshift, new_size, new_entries || @entries, new_children || @children)
|
152
144
|
else
|
153
145
|
self
|
154
146
|
end
|
@@ -172,7 +164,7 @@ module Immutable
|
|
172
164
|
@children[index] = child.put!(key, value)
|
173
165
|
@size += child.size - old_child_size
|
174
166
|
else
|
175
|
-
@children[index] = Trie.new(@
|
167
|
+
@children[index] = Trie.new(@bitshift + 5).put!(key, value)
|
176
168
|
@size += 1
|
177
169
|
end
|
178
170
|
end
|
@@ -193,7 +185,7 @@ module Immutable
|
|
193
185
|
|
194
186
|
# Returns a copy of <tt>self</tt> with the given key (and associated value) deleted. If not found, returns <tt>self</tt>.
|
195
187
|
def delete(key)
|
196
|
-
find_and_delete(key) || Trie.new(@
|
188
|
+
find_and_delete(key) || Trie.new(@bitshift)
|
197
189
|
end
|
198
190
|
|
199
191
|
# Delete multiple elements from a Trie. This is more efficient than
|
@@ -238,7 +230,7 @@ module Immutable
|
|
238
230
|
end
|
239
231
|
|
240
232
|
if new_entries || new_children
|
241
|
-
Trie.new(@
|
233
|
+
Trie.new(@bitshift, new_size, new_entries || @entries, new_children || @children)
|
242
234
|
else
|
243
235
|
self
|
244
236
|
end
|
@@ -277,7 +269,7 @@ module Immutable
|
|
277
269
|
end
|
278
270
|
true
|
279
271
|
end
|
280
|
-
alias
|
272
|
+
alias == eql?
|
281
273
|
|
282
274
|
protected
|
283
275
|
|
@@ -297,7 +289,7 @@ module Immutable
|
|
297
289
|
children = @children.dup
|
298
290
|
children[index] = copy
|
299
291
|
new_size = @size - (child.size - copy_size(copy))
|
300
|
-
return Trie.new(@
|
292
|
+
return Trie.new(@bitshift, new_size, @entries, children)
|
301
293
|
end
|
302
294
|
end
|
303
295
|
end
|
@@ -318,14 +310,14 @@ module Immutable
|
|
318
310
|
else
|
319
311
|
entries[index] = nil
|
320
312
|
end
|
321
|
-
Trie.new(@
|
313
|
+
Trie.new(@bitshift, @size - 1, entries, children || @children)
|
322
314
|
end
|
323
315
|
end
|
324
316
|
|
325
317
|
private
|
326
318
|
|
327
319
|
def index_for(key)
|
328
|
-
(key.hash.abs >> @
|
320
|
+
(key.hash.abs >> @bitshift) & 31
|
329
321
|
end
|
330
322
|
|
331
323
|
def copy_size(copy)
|
@@ -334,5 +326,5 @@ module Immutable
|
|
334
326
|
end
|
335
327
|
|
336
328
|
# @private
|
337
|
-
EmptyTrie = Trie.new(0)
|
329
|
+
EmptyTrie = Trie.new(0).freeze
|
338
330
|
end
|