Some information
I am working on a program that works with basic sets and antichains.
Antichains are subsets of the strength set of a set, so no two elements (sets) in this subset are subsets of another element (set) in this subset. For example, {{1}, {1,2}} is not antichain because {1} β {1,2}.
Some of the most important operations on antichains A and B can be defined as
- a.join (b) = sup (a βͺ b)
- a.meet (b) = sup ({X β© Y | X β a and Y β b})
Where sup is supremum of anticein, which means the smallest antichin is greater than a given set.
Presentation bye
The basic set is represented by long , bitarray-alike. This means that each element of the set is represented by the symbol 1 in bittra. For example, the set {1,2,3} is represented by 7 (bitrari 111), and the set {1,2,4} is represented by 11 (bitrari 1011), etc.
Now I wanted to raise this view in order to similarly present the anti-shops. This means that I could represent antichain {{1}, {2,3}} as 1000010 in bitarray, because long-term preservation of the set {1} is 1, and for {2,3} it is 6 (indices 1 in bitarray )
If I donβt find some better alternatives, I will use the BitSet class to work with this bitarray, hoping to save some time on working with any Collection<T> .
I have already managed to define and optimize most of the elementary operations indicated earlier, but they were optimized in the old version, just using TreeSet , therefore not optimized for working with bitarray.
My questions
- My question now is whether BitSet is the optimal representation, knowing that these bitarray representations double in size each time an element is added to the original set. I also thought of
BigInteger , for example, having the advantage of being comparable (which I also need). - I would also like to know if someone has already done something, and knows how to implement a connection and communicate effectively using the bitarray properties.
Thanks in advance.
Edit:
The code for my connection and meeting looks like this: at the moment:
public AntiChain join(AntiChain ac) { AntiChain res = new AntiChain(this); for(int i = ac.bitset.nextSetBit(0); i >= 0; i = ac.bitset.nextSetBit(i+1)) { res.addAndMakeAntiChain(new BasicSet(i)); } return res; } public AntiChain meet(AntiChain ac) { AntiChain res = AntiChain.emptyAntiChain(this.getUniverse()); for(int i = bitset.nextSetBit(0); i >= 0; i = bitset.nextSetBit(i+1)) for(int j = ac.bitset.nextSetBit(0); j >= 0; j = ac.bitset.nextSetBit(j+1)) res.addAndMakeAntiChain(new BasicSet(j).intersection(new BasicSet(i))); return res; } private void addAndMakeAntiChain(BasicSet x) { for(int k = bitset.nextSetBit(0); k >= 0; k = bitset.nextSetBit(k+1)) { BasicSet a = new BasicSet(k);