Commit Graph

22 Commits

Author SHA1 Message Date
Bill Currie a01cafe972 [util] Minimize set growth
At the low level, only unions can cause a set to grow. Of course, things
get interesting at the higher level when infinite (inverted) sets are
mixed in.
2021-08-11 12:31:03 +09:00
Bill Currie 37a5b475c0 [util] Minimize the string for infinite sets
Instead of printing every representable member of an infinite set (ie,
up to element 63 in a set that can hold 64 elements), only those
elements up to one after the last non-member are listed. For example,

    {...} - {2 3} -> {0 1 4 ...}

This makes reading (and testing!) infinite sets much easier.
2021-08-11 12:31:03 +09:00
Bill Currie aa72f1dc31 [util] Fix reversed finite-infinite set union ops
It looks like I tried to test it, but my tests weren't so good This
seems to cover everything for the three main set ops.
2021-08-11 12:31:03 +09:00
Bill Currie b320c3352f [util] Make set_t endian-agnostic
Most of the set ops were always endian-agnostic since they were simply
operating on multiple bits in parallel, but individual element
add/remove/test was very endian-dependent. For the most part, this
didn't matter, but it does matter very much when loading external data
into a set or writing the data out (eg, for PVS).
2021-08-08 12:34:18 +09:00
Bill Currie 163d147044 [util] Give set_count a >8x speed boost
I knew counting bits individually was slow, but it never really mattered
until now. However, I didn't expect such a dramatic boost just by going
to mapping bytes to bit counts. 16-bit words would be faster still, but
the 64kB lookup table would probably start hurting cache performance,
and 32-bit words (4GB table) definitely would ruin the cache. The
universe isn't big enough for 64-bits :)
2021-07-27 13:54:22 +09:00
Bill Currie 49c3dacbbc [util] Rename set_size to set_count
After seeing set_size and thinking it redundant (thought it returned the
capacity of the set until I checked), I realized set_count would be a
much better name (set_count (node->successors) in qfcc does make much
more sense).
2021-07-27 11:52:21 +09:00
Bill Currie 03921c03c5 [util] Expose set_expand and fix an out-by-one bug
Having set_expand exposed is useful for loading data into a set.

However, it turns out there was a bug in its size calculation in that
when the requested set size was a multiple of SET_BITS (and greater than
the current set size), the new set size one be SET_BITS larger than
requested. There's now some tests for this :)
2021-07-26 09:54:03 +09:00
Bill Currie 00aa584506 [util] Add re-entrant set_as_string
Makes it easier to debug set-related code in multi-threaded code.
2021-03-28 20:25:57 +09:00
Bill Currie 34bcf7faab Do a pure/const/noreturn/format attribute pass.
I always wanted these, but as gcc now provides warnings for functions that
could do with such attributes, finding all the functions is much easier.
2018-10-09 12:42:21 +09:00
Bill Currie 247f3be0c0 Create reentrant versions of the set functions that need it.
Only the functions that allocate or delete sets or iterators.
2013-03-18 13:20:39 +09:00
Bill Currie 27bb337a60 Use set_bits_t for holding set elements.
set_bits_t is now 64 bits for x86_64 machines (in linux, anyway). This gave
qfvis a huge speed boost: from ~815s to ~720s.

Also, expose some of the set internals so custom set operators can be
created.
2013-03-16 21:26:49 +09:00
Bill Currie ca0b03687f Change the naming of ALLOC's free-list.
Rather than prefixing free_ to the supplied name, suffix _freelist to the
supplied name. The biggest advantage of this is it allows the free-list to
be a structure member. It also cleans up the name-space a little.
2013-03-08 22:16:31 +09:00
Bill Currie eb2828e11c Add a function to pre-allocate space for a large set.
When the maximum set size is large but constant, and members will be added
one at a time, growing the set dynamically is not very efficient.
2013-03-07 10:27:30 +09:00
Bill Currie 84a68b139e Rename set_iter_t's value to element.
Correct terminology and all :)
2012-12-21 14:09:00 +09:00
Bill Currie 6473951daa Make the set notation more correct.
The empty set is now {}, the set of everything is now {...} and the rest
now have {} around the members.
2012-12-09 22:17:55 +09:00
Bill Currie 061e2be5d4 Re-write the set testing code.
Getting everything right with an enum proved to be too difficult if not
impossible. Also use better tests for equivalence and intersection.

Many more tests have been added. All pass :)
2012-12-09 13:52:48 +09:00
Bill Currie 94e804d786 Make some more set_test fixes.
Two inverted sets can never be disjoint.
2012-12-07 22:25:36 +09:00
Bill Currie 56956fc370 Rewrite the intersection tests.
The early bailout proved to be difficult to get right, so don't bother.
2012-12-07 22:16:51 +09:00
Bill Currie b053edee17 Fix the handling of size in set_expand.
It was correct for set_add, but not for other ops :/ (out by 1)
2012-12-07 20:44:09 +09:00
Bill Currie 39920a4ea7 Fix the type when converting set of everything to string. 2012-12-07 19:35:37 +09:00
Bill Currie e0c92b6089 Rename set_iter_t's member to value.
Makes more sense now that the membership of the value depends on the
inversion of the set.
2012-12-06 21:11:38 +09:00
Bill Currie eb8fd55677 Move set.c into libQFutil.
Also move the ALLOC/FREE macros from qfcc.h to QF/alloc.h (needed to for
set.c).

Both modules are more generally useful than just for qfcc (eg, set
builtins for ruamoko).
2012-12-06 20:52:53 +09:00
Renamed from tools/qfcc/source/set.c (Browse further)