diff options
author | steven <steven@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-07-26 12:02:54 +0000 |
---|---|---|
committer | steven <steven@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-07-26 12:02:54 +0000 |
commit | 4f862fce4a1472026631923d26ef754f21c67c73 (patch) | |
tree | b377f47b8511c1d1b93b64e5b37aef519af1940b /gcc/sparseset.h | |
parent | a1fef274251d6a7050d29583b2101ce053ed48dc (diff) | |
download | gcc-4f862fce4a1472026631923d26ef754f21c67c73.tar.gz |
* bitmap.h: Add explanation of sparse set as linked-list bitmap.
* sbitmap.h: Add explanation about non-sparse sets as simple bitmap.
(TEST_BIT): Make a static inline function for stronger type checking.
(SET_BIT): Don't handle sbitmaps with popcount.
(RESET_BIT): Likewise.
(SET_BIT_WITH_POPCOUNT): New, like SET_BIT but with popcount.
(RESET_BIT_WITH_POPCOUNT): New, like RESET_BIT but with popcount.
* ebitmap.c (ebitmap_clear_bit): Use SET_BIT_WITH_POPCOUNT and
RESET_BIT_WITH_POPCOUNT on wordmask bitmaps.
(ebitmap_set_bit, ebitmap_and_into, ebitmap_and, ebitmap_ior_into,
ebitmap_and_compl_into, ebitmap_and_compl): Likewise.
* sparseset.h: Add explanation of sparse set representation.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@189888 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/sparseset.h')
-rw-r--r-- | gcc/sparseset.h | 68 |
1 files changed, 64 insertions, 4 deletions
diff --git a/gcc/sparseset.h b/gcc/sparseset.h index c177d2d456d..b215c55e9f3 100644 --- a/gcc/sparseset.h +++ b/gcc/sparseset.h @@ -1,5 +1,5 @@ /* SparseSet implementation. - Copyright (C) 2007, 2010 Free Software Foundation, Inc. + Copyright (C) 2007-2012 Free Software Foundation, Inc. Contributed by Peter Bergner <bergner@vnet.ibm.com> This file is part of GCC. @@ -21,11 +21,71 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_SPARSESET_H #define GCC_SPARSESET_H -#define SPARSESET_ELT_BITS ((unsigned) HOST_BITS_PER_WIDEST_FAST_INT) -#define SPARSESET_ELT_TYPE unsigned int +/* Implementation of the Briggs and Torczon sparse set representation. + The sparse set representation was first published in: + + "An Efficient Representation for Sparse Sets", + ACM LOPLAS, Vol. 2, Nos. 1-4, March-December 1993, Pages 59-69. + + The sparse set representation is suitable for integer sets with a + fixed-size universe. Two vectors are used to store the members of + the set. If an element I is in the set, then sparse[I] is the + index of I in the dense vector, and dense[sparse[I]] == I. The dense + vector works like a stack. The size of the stack is the cardinality + of the set. + + The following operations can be performed in O(1) time: + + * clear : sparseset_clear + * cardinality : sparseset_cardinality + * set_size : sparseset_size + * member_p : sparseset_bit_p + * add_member : sparseset_set_bit + * remove_member : sparseset_clear_bit + * choose_one : sparseset_pop + + Additionally, the sparse set representation supports enumeration of + the members in O(N) time, where n is the number of members in the set. + The members of the set are stored cache-friendly in the dense vector. + This makes it a competitive choice for iterating over relatively sparse + sets requiring operations: + + * forall : EXECUTE_IF_SET_IN_SPARSESET + * set_copy : sparseset_copy + * set_intersection : sparseset_and + * set_union : sparseset_ior + * set_difference : sparseset_and_compl + * set_disjuction : (not implemented) + * set_compare : sparseset_equal_p + + NB: It is OK to use remove_member during EXECUTE_IF_SET_IN_SPARSESET. + The iterator is updated for it. + + Based on the efficiency of these operations, this representation of + sparse sets will often be superior to alternatives such as simple + bitmaps, linked-list bitmaps, array bitmaps, balanced binary trees, + hash tables, linked lists, etc., if the set is sufficiently sparse. + In the LOPLAS paper the cut-off point where sparse sets became faster + than simple bitmaps (see sbitmap.h) when N / U < 64 (where U is the + size of the universe of the set). + + Because the set universe is fixed, the set cannot be resized. For + sparse sets with initially unknown size, linked-list bitmaps are a + better choice, see bitmap.h. + + Sparse sets storage requirements are relatively large: O(U) with a + larger constant than sbitmaps (if the storage requirement for an + sbitmap with universe U is S, then the storage required for a sparse + set for the same universe are 2*HOST_BITS_PER_WIDEST_FAST_INT * S). + Accessing the sparse vector is not very cache-friendly, but iterating + over the members in the set is cache-friendly because only the dense + vector is used. */ /* Data Structure used for the SparseSet representation. */ +#define SPARSESET_ELT_BITS ((unsigned) HOST_BITS_PER_WIDEST_FAST_INT) +#define SPARSESET_ELT_TYPE unsigned HOST_WIDEST_FAST_INT + typedef struct sparseset_def { SPARSESET_ELT_TYPE *dense; /* Dense array. */ @@ -107,7 +167,7 @@ sparseset_set_bit (sparseset s, SPARSESET_ELT_TYPE e) sparseset_insert_bit (s, e, s->members++); } -/* Return and remove an arbitrary element from the set S. */ +/* Return and remove the last member added to the set S. */ static inline SPARSESET_ELT_TYPE sparseset_pop (sparseset s) |