Sparse.xcc

Nikola Puzovic (Nikola.Puzovicst.com) Benoit Dupont de Dinechin (Benoit.Dupont-de-Dinechinst.com)

Copyright 2007 STMicroelectronics.

This program is free software; you can redistribute it and/or modify it under the terms of either (at your option): the GNU General Public License (GPL) version 2; the GNU Lesser General Public License (LGPL) version 2.1; any later version of these licences as published by the Free Software Foundation.

Sparse— Unsigned integer set implemented as sparse set (Briggs & Torczon).
struct Sparse_ {
  //@args       Memory memory, int32_t universe
  Memory MEMORY;
  int32_t UNIVERSE;
  int32_t COUNT;
  struct SparseEntry_ *ENTRIES;
};
Sparse_empty— Empty this Sparse
void
Sparse_empty(Sparse this);
Sparse_isEmpty— True iff this Sparse is empty.
static inline bool
Sparse_isEmpty(const_Sparse this)
{
  return Sparse_COUNT(this) == 0;
}
Sparse_isSingle— True iff this Sparse contains a single member.
#define Sparse_isSingle(this)   (Sparse_count(this) == 1)
Sparse_count— Count members contained in the Sparse set.
Return
The count of members in this Sparse set.
static inline int32_t
Sparse_count(const_Sparse this)
{
  return Sparse_COUNT(this);
}
Sparse_contains— Test a member for containment.
Return
True if this Sparse contains member.
bool
Sparse_contains(const_Sparse this, SparseMember member);
Sparse_insert— Insert a member in this Sparse set.
Return
False iff member was already contained in this Sparse set.
bool
Sparse_insert(Sparse this, SparseMember member);
Sparse_remove— Remove a member from this Sparse set.
Return
False iff member was not contained in this Sparse set.
bool
Sparse_remove(Sparse this, SparseMember member);
Sparse_choose— Choose and remove a member of the Sparse set.
SparseMember
Sparse_choose(Sparse this);
Sparse_equals— Test for Sparse equality.
bool
Sparse_equals(const_Sparse this, const_Sparse that);
Sparse_union— Union of this Sparse with that Sparse set.
bool
Sparse_union(Sparse this, const_Sparse that);
Sparse_inter— Intersect this Sparse with that Sparse set.
bool
Sparse_inter(Sparse this, const_Sparse that);
Sparse_diff— Remove that Sparse members from this Sparse set.
bool
Sparse_diff(Sparse this, const_Sparse that);
Sparse_position— Return the position of a member in this Sparse set.

Useful to get a dense index for the member.

static inline uint32_t
Sparse_position(const_Sparse this, SparseMember member)
{
  SparseEntry entries = Sparse_ENTRIES(this);
  return SparseEntry_POSITION(entries + member);
}
Sparse_entries— For use by Sparse_FOREACH.
static inline const struct SparseEntry_ *
Sparse_entries(const_Sparse this)
{
  return Sparse_ENTRIES(this);
}
Sparse_FOREACH— Iterates over the Sparse entries.
#define Sparse_FOREACH(this, iter) { \
  const struct SparseEntry_ *Sparse_ENTRIES = Sparse_entries(this); \
  int32_t Sparse_COUNT = Sparse_count(this), Sparse_POSITION = 0; \
  for (; Sparse_POSITION < Sparse_COUNT; Sparse_POSITION++) { \
    const_SparseEntry Sparse_ENTRY = Sparse_ENTRIES + Sparse_POSITION; \
    SparseMember iter = SparseEntry_MEMBER(Sparse_ENTRY);
#define Sparse_ENDEACH \
  } \
}