Initial commit
[cgperf.git] / positions.h
blob7e1698c33ca484879b5a3454c8d9001d5cdaaaa9
1 #ifndef CGPERF_POSITIONS_H
2 #define CGPERF_POSITIONS_H
3 #include <stdbool.h>
4 #include "c_fixing.h"
5 /*------------------------------------------------------------------------------------------------*/
6 #include "namespace/positions.h"
7 /*------------------------------------------------------------------------------------------------*/
8 /*{{{ Positions */
9 struct PositionIterator;
10 struct PositionReverseIterator;
11 /*{{{ constants */
12 enum {
14 * Maximum key position specifiable by the user, 1-based. Note that max_key_pos-1 must fit
15 * into the element type of positions[], below.
17 POS_MAX_KEY_POS = 255,
18 /* Denotes the last char of a keyword, depending on the keyword's length */
19 POS_LASTCHAR = -1,
21 * Maximum possible size. Since duplicates are eliminated and the possible 0-based positions
22 * are -1..max_key_pos-1, this is:
24 POS_MAX_SIZE = POS_MAX_KEY_POS + 1,
26 /*}}} constants -- END */
27 /*{{{ types */
28 struct Positions {
29 /*{{{ public */
31 * array of positions. 0 for the first char, 1 for the second char etc., lastchar for the
32 * last char
34 s32 positions[POS_MAX_SIZE];
35 /* number of positions */
36 u32 size;
37 /*}}} public -- END */
38 /*{{{ private */
39 /* The special case denoted by '*' */
40 bool useall;
41 /*}}} private -- END */
43 /*}}} types -- END */
44 /*{{{ public static methods */
45 static struct Positions *pos_new(void);
46 static struct Positions *pos_new_cpy(struct Positions *src);
47 static void pos_print(struct Positions *t);
48 static void pos_del(struct Positions *t);
49 static bool pos_contains(struct Positions *t, s32 pos);
50 static void pos_add(struct Positions *t, s32 pos);
51 static void pos_remove(struct Positions *t, s32 pos);
52 /* Write access */
53 static void pos_set_useall(struct Positions *t, bool useall);
54 static bool pos_sort(struct Positions *t);
55 static struct PositionIterator *pos_iterator(struct Positions *t, s32 maxlen);
56 static struct PositionIterator *pos_iterator_all(struct Positions *t);
57 static struct PositionReverseIterator *pos_reviterator(struct Positions *t);
58 static void pos_cpy(struct Positions *d, struct Positions *s);
59 /*}}} public static methods -- END */
60 /*}}} Position -- END */
61 /*{{{ PositionIterator */
62 /*{{{ constants */
63 enum {
64 /* end of iteration marker */
65 POSITER_EOS = -2,
67 /*}}} constants -- END */
68 /*{{{ types */
69 struct PositionIterator {
70 /*{{{ private */
71 struct Positions *set;
72 u32 index;
73 /*}}}*/
75 /*}}} types -- END */
76 /*{{{ public static methods */
77 static struct PositionIterator *positer_new(struct Positions *positions, s32 maxlen);
78 static struct PositionIterator *positer_new_all(struct Positions *positions);
79 static void positer_del(struct PositionIterator *t);
80 static u32 positer_remaining(struct PositionIterator *t);
81 static s32 positer_next(struct PositionIterator *t);
82 /*}}} public static methods -- END */
83 /*}}} PositionIterator -- END */
84 /*{{{ PositionReverseIterator */
85 /*{{{ constants and types */
86 enum {
87 /* end of iteration marker */
88 POSREVIT_EOS = -2,
90 struct PositionReverseIterator {
91 /*{{{ private */
92 struct Positions *set;
93 u32 index;
94 u32 minindex;
95 /*}}} private -- END */
97 /*}}} constants and types -- END */
98 /*{{{ public static methods */
99 static struct PositionReverseIterator *posrevit_new(struct Positions *positions);
100 static void posrevit_del(struct PositionReverseIterator *t);
101 static s32 posrevit_next(struct PositionReverseIterator *t);
102 /*}}} public static methods -- END */
103 /*}}} PositionReverseIterator -- END */
104 /*------------------------------------------------------------------------------------------------*/
105 #define EPILOG
106 #include "namespace/positions.h"
107 #undef EPILOG
108 /*------------------------------------------------------------------------------------------------*/
109 #endif