makingthematrix / gailibrary

A very cheerful library for Artificial Intelligence in games
MIT License
7 stars 0 forks source link

Optimize USet (and UMap) #43

Open makingthematrix opened 6 years ago

makingthematrix commented 6 years ago
  1. Introduce offset. The first value of the set should be always true and the offset tells us what should we add to its index. It might be a bit slower for simply checking if the set contains the value, but the operations on sets should be faster, as there will be no idle processing of the initial empty part of the vector.
  2. Similarly, find a smart way to trim the set at the end. The last value of the set should always be true. With (1) and (2) done the equality of two sets could be measured by simply comparing the vectors. Right now two sets can be equal even if their vectors differ because of their empty initial and final parts. On the other hand, to ensure this, removing the first or the last element in the set will require copying the whole vector... But I don't think users will do that very often.
  3. The xor method is now trivial: A ^ B == (A + B) - (A * B). It can be much faster.