quakeforge/tools/qfcc/include/set.h
Bill Currie b9599a7119 Better set memory management.
At the cost of one pointer per set, sets can now be allocated and freed
more efficiently (especially since malloc might round things up).
2012-11-15 13:44:07 +09:00

79 lines
2.2 KiB
C

/*
set.h
Set manipulation.
Copyright (C) 2012 Bill Currie <bill@taniwha.org>
Author: Bill Currie <bill@taniwha.org>
Date: 2012/8/4
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifndef set_h
#define set_h
/** \defgroup qfcc_set Set handling
\ingroup qfcc
*/
//@{
typedef struct set_s {
struct set_s *next; //< private. for ALLOC
unsigned *map;
unsigned size;
unsigned defmap[8];
} set_t;
typedef struct set_iter_s {
struct set_iter_s *next; //< private. for ALLOC
const set_t *set;
/** The result of set_first() or set_next(). set_next() will start at the
following member.
*/
unsigned member;
} set_iter_t;
void set_del_iter (set_iter_t *set_iter);
set_t *set_new (void);
void set_delete (set_t *set);
void set_add (set_t *set, unsigned x);
void set_remove (set_t *set, unsigned x);
set_t *set_union (set_t *dst, const set_t *src);
set_t *set_intersection (set_t *dst, const set_t *src);
set_t *set_difference (set_t *dst, const set_t *src);
set_t *set_assign (set_t *dst, const set_t *src);
set_t *set_empty (set_t *set);
int set_is_empty (const set_t *set);
int set_is_disjoint (const set_t *s1, const set_t *s2);
int set_is_intersecting (const set_t *s1, const set_t *s2);
int set_is_equivalent (const set_t *s1, const set_t *s2);
int set_is_subset (const set_t *set, const set_t *sub);
int set_is_member (const set_t *set, unsigned x);
unsigned set_size (const set_t *set);
set_iter_t *set_first (const set_t *set);
set_iter_t *set_next (set_iter_t *set_iter);
const char *set_as_string (const set_t *set);
//@}
#endif//set_h