Derive-C
Loading...
Searching...
No Matches
template.h File Reference

Go to the source code of this file.

Data Structures

struct  SELF
 An allocator that prints to stdout when it allocates or frees memory. More...
struct  ITER_CONST

Macros

#define ITEM   set_item_t
 A swisstable based hashset.
#define ITEM_HASH   item_hash
#define ITEM_EQ   DC_MEM_EQ
#define ITEM_DELETE   DC_NO_DELETE
#define ITEM_CLONE   DC_COPY_CLONE
#define ITEM_DEBUG   DC_DEFAULT_DEBUG
#define MAP   PRIV(NS(NAME, inner_map))
#define KEY   ITEM
#define KEY_HASH   ITEM_HASH
#define KEY_EQ   ITEM_EQ
#define KEY_DELETE   ITEM_DELETE
#define KEY_CLONE   ITEM_CLONE
#define KEY_DEBUG   ITEM_DEBUG
#define VALUE   dc_unit
#define VALUE_DELETE   dc_unit_delete
#define VALUE_CLONE   dc_unit_clone
#define VALUE_DEBUG   dc_unit_debug
#define INTERNAL_NAME   MAP
#define ITER_CONST   NS(SELF, iter_const)

Typedefs

typedef size_t ITEM
typedef ITEM const * item

Functions

static size_t ITEM_HASH (ITEM const *item)
static DC_PUBLIC SELF new_with_capacity_for (size_t for_items, ref alloc_ref)
static DC_PUBLIC SELF new (ref alloc_ref)
static DC_PUBLIC SELF clone (SELF const *self)
static DC_PUBLIC void extend_capacity_for (SELF *self, size_t expected_items)
static DC_PUBLIC bool try_add (SELF *self, ITEM item)
static DC_PUBLIC void add (SELF *self, ITEM item)
static DC_PUBLIC bool contains (SELF const *self, ITEM item)
static DC_PUBLIC bool try_remove (SELF *self, ITEM item)
static DC_PUBLIC void remove (SELF *self, ITEM item)
static DC_PUBLIC size_t size (SELF const *self)
static DC_PUBLIC bool empty_item (ITEM const *const *item)
static DC_PUBLIC ITEM const * next (ITER_CONST *iter)
static DC_PUBLIC bool empty (ITER_CONST const *iter)
static DC_PUBLIC ITER_CONST get_iter_const (SELF const *self)
static DC_PUBLIC void debug (SELF const *self, dc_debug_fmt fmt, FILE *stream)
static DC_PUBLIC void delete (SELF *self)
 DC_TRAIT_SET (SELF)

Variables

DC_STATIC_CONSTANT size_t max_capacity = max_capacity

Macro Definition Documentation

◆ INTERNAL_NAME

#define INTERNAL_NAME   MAP

Definition at line 60 of file template.h.

◆ ITEM

#define ITEM   set_item_t

A swisstable based hashset.

Definition at line 15 of file template.h.

◆ ITEM_CLONE

#define ITEM_CLONE   DC_COPY_CLONE

Definition at line 37 of file template.h.

◆ ITEM_DEBUG

#define ITEM_DEBUG   DC_DEFAULT_DEBUG

Definition at line 41 of file template.h.

◆ ITEM_DELETE

#define ITEM_DELETE   DC_NO_DELETE

Definition at line 33 of file template.h.

◆ ITEM_EQ

#define ITEM_EQ   DC_MEM_EQ

Definition at line 29 of file template.h.

◆ ITEM_HASH

#define ITEM_HASH   item_hash

Definition at line 24 of file template.h.

◆ ITER_CONST

#define ITER_CONST   NS(SELF, iter_const)

Definition at line 118 of file template.h.

◆ KEY

#define KEY   ITEM

Definition at line 50 of file template.h.

◆ KEY_CLONE

#define KEY_CLONE   ITEM_CLONE

Definition at line 54 of file template.h.

◆ KEY_DEBUG

#define KEY_DEBUG   ITEM_DEBUG

Definition at line 55 of file template.h.

◆ KEY_DELETE

#define KEY_DELETE   ITEM_DELETE

Definition at line 53 of file template.h.

◆ KEY_EQ

#define KEY_EQ   ITEM_EQ

Definition at line 52 of file template.h.

◆ KEY_HASH

#define KEY_HASH   ITEM_HASH

Definition at line 51 of file template.h.

◆ MAP

#define MAP   PRIV(NS(NAME, inner_map))

Definition at line 46 of file template.h.

◆ VALUE

#define VALUE   dc_unit

Definition at line 56 of file template.h.

◆ VALUE_CLONE

#define VALUE_CLONE   dc_unit_clone

Definition at line 58 of file template.h.

◆ VALUE_DEBUG

#define VALUE_DEBUG   dc_unit_debug

Definition at line 59 of file template.h.

◆ VALUE_DELETE

#define VALUE_DELETE   dc_unit_delete

Definition at line 57 of file template.h.

Typedef Documentation

◆ ITEM

typedef size_t ITEM

Definition at line 16 of file template.h.

◆ item

typedef ITEM const* item

Definition at line 124 of file template.h.

Function Documentation

◆ add()

DC_PUBLIC void add ( SELF * self,
ITEM item )
static

Definition at line 97 of file template.h.

97 {
98 bool const inserted = NS(SELF, try_add)(self, item);
99 DC_ASSERT(inserted, "Failed to insert item");
100}
IV_PAIR item
Definition template.h:281
static DC_PUBLIC bool try_add(SELF *self, ITEM item)
Definition template.h:93
#define SELF
Definition def.h:52
#define NS(pre, post)
Definition namespace.h:14
#define DC_ASSERT(expr,...)
Definition panic.h:37

◆ clone()

DC_PUBLIC SELF clone ( SELF const * self)
static

Definition at line 83 of file template.h.

83 {
84 return (SELF){
85 .map = NS(MAP, clone)(&self->map),
86 };
87}
static DC_PUBLIC SELF clone(SELF const *self)
Definition template.h:215
#define MAP
Definition template.h:46

◆ contains()

DC_PUBLIC bool contains ( SELF const * self,
ITEM item )
static

Definition at line 102 of file template.h.

102 {
103 return NS(MAP, try_read)(&self->map, item) != NULL;
104}
static DC_PUBLIC VALUE const * try_read(SELF const *self, INDEX index)
Definition template.h:180

◆ DC_TRAIT_SET()

DC_TRAIT_SET ( SELF )

◆ debug()

DC_PUBLIC void debug ( SELF const * self,
dc_debug_fmt fmt,
FILE * stream )
static

Definition at line 143 of file template.h.

143 {
144 fprintf(stream, DC_EXPAND_STRING(SELF) "@%p {\n", (void*)self);
145 fmt = dc_debug_fmt_scope_begin(fmt);
146
147 dc_debug_fmt_print(fmt, stream, "map: ");
148 NS(MAP, debug)(&self->map, fmt, stream);
149 fprintf(stream, ",\n");
150
151 fmt = dc_debug_fmt_scope_end(fmt);
152 dc_debug_fmt_print(fmt, stream, "}");
153}
static DC_PUBLIC void debug(SELF const *self, dc_debug_fmt fmt, FILE *stream)
Definition template.h:212
static DC_PUBLIC void dc_debug_fmt_print(dc_debug_fmt fmt, FILE *stream, const char *format,...)
Definition fmt.h:32
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_end(dc_debug_fmt fmt)
Definition fmt.h:57
static DC_PUBLIC dc_debug_fmt dc_debug_fmt_scope_begin(dc_debug_fmt fmt)
Definition fmt.h:50
#define DC_EXPAND_STRING(NAME)
Definition namespace.h:6
static DC_PUBLIC FILE * stream(SELF *self)
Definition template.h:108

◆ delete()

DC_PUBLIC void delete ( SELF * self)
static

Definition at line 157 of file template.h.

157{ NS(MAP, delete)(&self->map); }
MAP map
Definition template.h:68

◆ empty()

DC_PUBLIC bool empty ( ITER_CONST const * iter)
static

Definition at line 132 of file template.h.

132 {
133 DC_ASSUME(iter);
134 return NS(MAP, NS(iter_const, empty))(&iter->map_iter);
135}
static DC_PUBLIC bool empty(ITER const *iter)
Definition template.h:349
#define DC_ASSUME(expr,...)
Definition panic.h:57

◆ empty_item()

DC_PUBLIC bool empty_item ( ITEM const *const * item)
static

Definition at line 126 of file template.h.

126{ return *item == NULL; }

◆ extend_capacity_for()

DC_PUBLIC void extend_capacity_for ( SELF * self,
size_t expected_items )
static

Definition at line 89 of file template.h.

89 {
90 NS(MAP, extend_capacity_for)(&self->map, expected_items);
91}
static DC_PUBLIC void extend_capacity_for(SELF *self, size_t expected_items)
Definition template.h:307

◆ get_iter_const()

DC_PUBLIC ITER_CONST get_iter_const ( SELF const * self)
static

Definition at line 137 of file template.h.

137 {
138 return (ITER_CONST){
139 .map_iter = NS(MAP, get_iter_const)(&self->map),
140 };
141}
#define ITER_CONST
Definition template.h:411
static DC_PUBLIC ITER_CONST get_iter_const(SELF const *self)
Definition template.h:464

◆ ITEM_HASH()

size_t ITEM_HASH ( ITEM const * item)
static

Definition at line 25 of file template.h.

25{ return *item; }

◆ new()

DC_PUBLIC SELF new ( ref alloc_ref)
static

Definition at line 77 of file template.h.

77 {
78 return (SELF){
79 .map = NS(MAP, new)(alloc_ref),
80 };
81}

◆ new_with_capacity_for()

DC_PUBLIC SELF new_with_capacity_for ( size_t for_items,
ref alloc_ref )
static

Definition at line 71 of file template.h.

71 {
72 return (SELF){
73 .map = NS(MAP, new_with_capacity_for)(for_items, alloc_ref),
74 };
75}
static DC_PUBLIC SELF new_with_capacity_for(INDEX_TYPE items, ref alloc_ref)
Definition template.h:96

◆ next()

DC_PUBLIC ITEM const * next ( ITER_CONST * iter)
static

Definition at line 128 of file template.h.

128 {
129 return NS(MAP, NS(iter_const, next))(&iter->map_iter).key;
130}
static DC_PUBLIC IV_PAIR next(ITER *iter)
Definition template.h:355
iter_const map_iter
Definition template.h:121

◆ remove()

DC_PUBLIC void remove ( SELF * self,
ITEM item )
static

Definition at line 111 of file template.h.

111 {
112 bool const removed = NS(SELF, try_remove)(self, item);
113 DC_ASSERT(removed, "Failed to remove item {item=%s}", DC_DEBUG(ITEM_DEBUG, &item));
114}
#define ITEM_DEBUG
Definition template.h:39
static DC_PUBLIC bool try_remove(SELF *self, INDEX index, VALUE *destination)
Definition template.h:264
#define DC_DEBUG(DEBUG_FN, DEBUG_PTR)
Definition dump.h:92

◆ size()

DC_PUBLIC size_t size ( SELF const * self)
static

Definition at line 116 of file template.h.

116{ return NS(MAP, size)(&self->map); }
static DC_PUBLIC size_t size(SELF const *self)
Definition template.h:252

◆ try_add()

DC_PUBLIC bool try_add ( SELF * self,
ITEM item )
static

Definition at line 93 of file template.h.

93 {
94 return NS(MAP, try_insert)(&self->map, item, dc_unit_new()) != NULL;
95}
static DC_PUBLIC VALUE * try_insert(SELF *self, KEY key, VALUE value)
Definition template.h:318
static DC_PUBLIC dc_unit dc_unit_new()
Definition unit.h:9

◆ try_remove()

DC_PUBLIC bool try_remove ( SELF * self,
ITEM item )
static

Definition at line 106 of file template.h.

106 {
107 dc_unit dest;
108 return NS(MAP, try_remove)(&self->map, item, &dest);
109}

Variable Documentation

◆ max_capacity

DC_STATIC_CONSTANT size_t max_capacity = max_capacity

Definition at line 65 of file template.h.