Skip to content
This repository has been archived by the owner on Feb 6, 2022. It is now read-only.
/ Handbag Public archive

Swift counted set for storing an unordered collection of non-unique elements

License

Notifications You must be signed in to change notification settings

JadenGeller/Handbag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Handbag

Bag is a counted set type suitable for representing unordered collections of non-unique elements. A Bag can be initialized from either a dictionary literal specifying the number of each type of element or from an array literal specifying the elements.

let blah: Bag = ["hi" : 3, "bye" : 2]
let bleh: Bag = ["hi", "hi", "hi", "bye", "bye"]

You can easily check the count of a given element in a Bag using subscript notation. Elements can easily be added and removed as well.

print(blah["hi"]) // -> 3
blah["hi"] += 2
blah.insert("hello", count: 7)
blah.remove("bye", count: 5)

Bag is a CollectionType that may contain multiple copies of each element. For example, mapping print over ["hi" : 3] will print "hi" three times.

Since Bag is a multiset, you can perform common set operations on it, such as union, subtract, and intersect. Further, you can check if a given Bag is a superset of, subset of, or is disjoint with another Bag.

About

Swift counted set for storing an unordered collection of non-unique elements

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages