prime bag
A bag datatype that used unsigned integers for storage. This works by assigning each possible item a prime number. The contents of the bag is represented by the product of those prime numbers. This works best if the set of possible items is constrained and some items are much more common than others. To maximize the possible size of the bag, assign lower prime numbers to more common items.
Using prime bags, certain operations can be done very efficiently: Adding an element or combining two bags is achieved by multiplication. Removing an element or bag of elements is achieved by division. Testing for the presence of an element is achieved by modulus.
| Set Operation | Math Operation |
|---|---|
| Insert / Extend | Multiplication |
| Remove | Division |
| Contains / Superset | Modulus |
| Intersection | Greatest Common Factor |
Elements of the Bag must implement PrimeBagElement
Getting started
use *;
;