mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
library/bag.m:
Add predicates and a function for efficiently inserting multiple copies of
an item into a bag.
NEWS:
Announce the above additions.
tests/hard_coded/bag_various.{m,exp}:
Extend this test to cover the above.
12 lines
578 B
Plaintext
12 lines
578 B
Plaintext
bag.to_list: [1, 1, 1, 2, 3, 3, 4]
|
|
bag.to_assoc_list: [1 - 3, 2 - 1, 3 - 2, 4 - 1]
|
|
bag.count: 7
|
|
bag.count_unique: 4
|
|
bag.member(4): yes
|
|
bag.member(5): no
|
|
unsorted_solutions(bag.member/3): [{4, [1, 1, 1, 2, 3, 3]}, {3, [1, 1, 1, 2, 3, 4]}, {3, [1, 1, 1, 2, 3, 4]}, {2, [1, 1, 1, 3, 3, 4]}, {1, [1, 1, 2, 3, 3, 4]}, {1, [1, 1, 2, 3, 3, 4]}, {1, [1, 1, 2, 3, 3, 4]}]
|
|
bag.insert_duplicates(5, "foo"): ["foo", "foo", "foo", "foo", "foo"]
|
|
bag.insert_duplicates(0, "foo"): []
|
|
bag.insert_duplicates(-1, "foo"): "fail"
|
|
bag.insert_duplicates(4, "foo"): ["foo", "foo", "foo", "foo", "foo"]
|