-
Notifications
You must be signed in to change notification settings - Fork 6
/
Set.HC
47 lines (47 loc) · 893 Bytes
/
Set.HC
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#ifndef SET_H
#define SET_H "gay frogballer"
class CI64Set {
I64 cnt,cap;
I64 *body;
};
U0 I64SetDel(CI64Set *s) {
Free(s->body);
Free(s);
}
CI64Set *I64SetNew() {
CI64Set *s=CAlloc(sizeof(CI64Set),doom_task);
s->cap=16;
s->body=CAlloc(16*8,doom_task);
return s;
}
Bool I64SetHas(CI64Set *s,I64 v) {
I64 i=s->cnt;
while(--i>=0)
if(s->body[i]==v)
return TRUE;
return FALSE;
}
Bool I64SetAdd(CI64Set *s,I64 v) {
if(I64SetHas(s,v)) return FALSE;
I64 *new;
if(s->cnt+1>=s->cap) {
new=CAlloc(MSize(s->body)+16*8,doom_task);
s->cap+=16;
MemCpy(new,s->body,s->cnt*8);
Free(s->body);
s->body=new;
}
s->body[s->cnt++]=v;
return TRUE;
}
U0 I64SetRem(CI64Set *s,I64 v) {
I64 idx,ptr=0,del=0;
for(idx=0;idx!=s->cnt;idx++) {
if(s->body[idx]!=v)
s->body[ptr++]=s->body[idx];
else
del++;
}
s->cnt-=del;
}
#endif