-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdigest.h
160 lines (133 loc) · 3.62 KB
/
digest.h
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#ifndef _DIGEST_H_
#define _DIGEST_H_
// a set of IDs, represented as a bitmap.
#define WORK_TYPE_MAX_ID 377
#define WORK_TYPE_NWORDS 12
#define INSTRUMENT_MAX_ID 173
#define INSTRUMENT_NWORDS 6
#define PERIOD_MAX_ID 35
#define PERIOD_NWORDS 2
#define NATIONALITY_MAX_ID 126
#define NATIONALITY_NWORDS 4
// max of the above cases
#define BITMAP_MAX_NWORDS 12
#define BITMAP_MAX_ID 377
#define INST_COMBO_MAX_ID 11218
#define INST_COMBO_NWORDS 351
struct BITMAP {
int bits[0];
inline void clear(int nwords) {
for (int i=0; i<nwords; i++) {
bits[i] = 0;
}
}
inline void set(int i) {
bits[i/32] |= 1<<(i%32);
}
inline bool is_set(int i) {
return bits[i/32] & 1<<(i%32);
}
// is ib2 a subset of this?
inline bool contains(BITMAP& ib2, int nwords) {
for (int i=0; i<nwords; i++) {
int b = ib2.bits[i];
if ((b & bits[i]) != b) return false;
}
return true;
}
// does ib2 overlap this?
inline bool overlaps(BITMAP& ib2, int nwords) {
for (int i=0; i<nwords; i++) {
int b = ib2.bits[i];
if (b & bits[i]) return true;
}
return false;
}
// is ib2 equal to this?
inline bool equals(BITMAP& ib2, int nwords) {
for (int i=0; i<nwords; i++) {
if (ib2.bits[i] != bits[i]) return false;
}
return true;
}
// OR ib2 into this bitmap
//
inline void set_multi(int* ib2, int nwords) {
for (int i=0; i<nwords; i++) {
bits[i] |= ib2[i];
}
}
};
// info from the work, score and recording tables,
// together with info from connected tables like composer.
//
// Depending on the query, a field can be part of a filter
// or part of the result.
//
// max # of instrument combos to store.
#define MAX_COMBOS 4
struct WORK {
char title[80]; // lower case
int work_id;
int work_type[WORK_TYPE_NWORDS];
int period_id;
int inst[INSTRUMENT_NWORDS];
// the union of the instruments in the work's inst combos
int inst_combos[MAX_COMBOS];
// instrument combo ids; 0 marks end of list
int comp_id;
int comp_nationality[NATIONALITY_NWORDS];
int comp_sex;
int year_of_first_publication;
};
struct SCORE {
char title[80];
int score_id;
int work_id;
int work_type[WORK_TYPE_NWORDS];
int period_id;
int inst[INSTRUMENT_NWORDS];
// if the score is an arrangement, the union of the combo insts
// else the work's instruments as above
int inst_combos[MAX_COMBOS];
// score inst combo, else work
int comp_id;
int comp_nationality[NATIONALITY_NWORDS];
int comp_sex;
int license_id;
int is_arrangement;
int publisher_id;
};
struct REC {
char title[80];
int rec_id;
int work_id;
int work_type[WORK_TYPE_NWORDS];
int period_id;
int inst[INSTRUMENT_NWORDS];
// if the rec is an arrangement, the union of the combo insts
// else the work's instruments as above
int inst_combos[MAX_COMBOS];
// score inst combo, else work
int comp_id;
int comp_nationality[NATIONALITY_NWORDS];
int comp_sex;
int license_id;
int is_arrangement;
};
// max #insts in a combo; digest.php prints this
#define MAX_INSTS 16
struct INST_COMBO {
int id;
int inst_id[MAX_INSTS+1]; // sorted; 0 marks end
int count[MAX_INSTS];
};
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
size_t file_size(const char* path) {
struct stat sbuf;
stat(path, &sbuf);
return sbuf.st_size;
}
#endif