flatdata 0.1.4

Rust implementation of heremaps/flatdata
Documentation
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
// Do not edit: This code was generated by flatdata's generator.

use flatdata::Struct;

pub mod schema {
    pub mod structs {
        pub const INDEX_TYPE32: &str =
            r#"namespace _builtin.multivector { struct IndexType32 { value : u64 : 32; } }"#;
        pub const DEGREE: &str = r#"namespace coappearances { struct Degree {
    value : u32 : 16;
} }"#;
        pub const INVARIANTS: &str = r#"namespace coappearances { struct Invariants {
    max_degree : u32 : 16;
    max_degree_ref : u32 : 16;
    min_degree : u32 : 16;
    min_degree_ref : u32 : 16;
    num_connected_components : u32 : 16;
} }"#;
        pub const STATISTICS: &str = r#"namespace coappearances { struct Invariants {
    max_degree : u32 : 16;
    max_degree_ref : u32 : 16;
    min_degree : u32 : 16;
    min_degree_ref : u32 : 16;
    num_connected_components : u32 : 16;
} }
namespace coappearances { struct Degree {
    value : u32 : 16;
} }
namespace coappearances { @bound_implicitly( characters: Graph.vertices, vertex_degrees )
archive Statistics {
    invariants : Invariants;

    // indexed by `vertices`
    vertex_degrees : vector< Degree >;
} }"#;
        pub const CHAPTER: &str = r#"namespace coappearances { /**
 * A chapter in the book.
 */
struct Chapter {
    major: u8 : 4;
    minor: u8 : 7;
} }"#;
        pub const BINARY_RELATION: &str = r#"namespace coappearances { /**
 * A relation of a character to two other characters.
 */
struct BinaryRelation {
    kind_ref: u32 : 32;
    to_a_ref: u32 : 16;
    to_b_ref: u32 : 16;
} }"#;
        pub const UNARY_RELATION: &str = r#"namespace coappearances { /**
 * A relation of a character to another one.
 */
struct UnaryRelation {
    kind_ref: u32 : 32;
    to_ref: u32 : 16;
} }"#;
        pub const DESCRIPTION: &str = r#"namespace coappearances { /**
 * A description of a character.
 */
struct Description {
    ref: u32 : 32;
} }"#;
        pub const NICKNAME: &str = r#"namespace coappearances { /**
 * A nickname or an alternative name of a character.
 */
struct Nickname {
    ref: u32 : 32;
} }"#;
        pub const COAPPEARANCE: &str = r#"namespace coappearances { /**
 * An appearance of two characters in the same scene.
 *
 * count - multiplicity of the coappearance.
 * first_chapter_ref - a reference to the first chapter in which characters appear. How to get the
 * full range of chapters is described in 'coappearances.cpp:read'.
 */
struct Coappearance {
    a_ref : u32 : 16;
    b_ref : u32 : 16;
    count : u32 : 16;
    first_chapter_ref: u32 : 16;
} }"#;
        pub const CHARACTER: &str = r#"namespace coappearances { /**
 * A character.
 */
struct Character {
    name_ref : u32 : 32;
} }"#;
        pub const META: &str = r#"namespace coappearances { /**
 * Meta information about the book.
 */
struct Meta {
    title_ref : u32 : 32;
    author_ref : u32 : 32;
} }"#;
        pub const GRAPH: &str = r#"namespace coappearances { /**
 * Meta information about the book.
 */
struct Meta {
    title_ref : u32 : 32;
    author_ref : u32 : 32;
} }
namespace coappearances { /**
 * A character.
 */
struct Character {
    name_ref : u32 : 32;
} }
namespace coappearances { /**
 * An appearance of two characters in the same scene.
 *
 * count - multiplicity of the coappearance.
 * first_chapter_ref - a reference to the first chapter in which characters appear. How to get the
 * full range of chapters is described in 'coappearances.cpp:read'.
 */
struct Coappearance {
    a_ref : u32 : 16;
    b_ref : u32 : 16;
    count : u32 : 16;
    first_chapter_ref: u32 : 16;
} }
namespace coappearances { /**
 * A nickname or an alternative name of a character.
 */
struct Nickname {
    ref: u32 : 32;
} }
namespace coappearances { /**
 * A description of a character.
 */
struct Description {
    ref: u32 : 32;
} }
namespace coappearances { /**
 * A relation of a character to another one.
 */
struct UnaryRelation {
    kind_ref: u32 : 32;
    to_ref: u32 : 16;
} }
namespace coappearances { /**
 * A relation of a character to two other characters.
 */
struct BinaryRelation {
    kind_ref: u32 : 32;
    to_a_ref: u32 : 16;
    to_b_ref: u32 : 16;
} }
namespace _builtin.multivector { struct IndexType32 { value : u64 : 32; } }
namespace coappearances { /**
 * A chapter in the book.
 */
struct Chapter {
    major: u8 : 4;
    minor: u8 : 7;
} }
namespace coappearances { @bound_implicitly( characters: Graph.vertices, vertex_degrees )
archive Statistics {
    invariants : Invariants;

    // indexed by `vertices`
    vertex_degrees : vector< Degree >;
} }
namespace coappearances { struct Invariants {
    max_degree : u32 : 16;
    max_degree_ref : u32 : 16;
    min_degree : u32 : 16;
    min_degree_ref : u32 : 16;
    num_connected_components : u32 : 16;
} }
namespace coappearances { struct Degree {
    value : u32 : 16;
} }
namespace coappearances { @bound_implicitly( characters: vertices, vertices_data )
archive Graph {
    @explicit_reference( Meta.title_ref, strings )
    @explicit_reference( Meta.author_ref, strings )
    meta : Meta;

    @explicit_reference( Character.name_ref, strings )
    vertices : vector< Character >;

    @explicit_reference( Coappearance.a_ref, vertices )
    @explicit_reference( Coappearance.b_ref, vertices )
    @explicit_reference( Coappearance.first_chapter_ref, chapters )
    edges : vector< Coappearance >;

    @explicit_reference( Nickname.ref, strings )
    @explicit_reference( Description.ref, strings )
    @explicit_reference( UnaryRelation.kind_ref, strings )
    @explicit_reference( UnaryRelation.to_ref, vertices )
    @explicit_reference( BinaryRelation.kind_ref, strings )
    @explicit_reference( BinaryRelation.to_a_ref, vertices )
    @explicit_reference( BinaryRelation.to_b_ref, vertices )
    vertices_data: multivector< 32, Nickname, Description, UnaryRelation, BinaryRelation >;

    chapters : vector< Chapter >;

    // All strings contained in the data separated by '\0'.
    strings: raw_data;

    // Optional archive containing calculated statistics.
    @optional
    statistics : archive Statistics;
} }"#;
    }

    pub mod resources {
        pub mod statistics {
            pub const INVARIANTS: &str = r#"namespace coappearances { struct Invariants {
    max_degree : u32 : 16;
    max_degree_ref : u32 : 16;
    min_degree : u32 : 16;
    min_degree_ref : u32 : 16;
    num_connected_components : u32 : 16;
} }
namespace coappearances { invariants : Invariants; }"#;
            pub const VERTEX_DEGREES: &str = r#"namespace coappearances { struct Degree {
    value : u32 : 16;
} }
namespace coappearances { // indexed by `vertices`
    vertex_degrees : vector< Degree >; }"#;
            pub const CHARACTERS: &str = r#"namespace coappearances { None }"#;
        }
        pub mod graph {
            pub const META: &str = r#"namespace coappearances { /**
 * Meta information about the book.
 */
struct Meta {
    title_ref : u32 : 32;
    author_ref : u32 : 32;
} }
namespace coappearances { @explicit_reference( Meta.title_ref, strings )
    @explicit_reference( Meta.author_ref, strings )
    meta : Meta; }"#;
            pub const VERTICES: &str = r#"namespace coappearances { /**
 * A character.
 */
struct Character {
    name_ref : u32 : 32;
} }
namespace coappearances { @explicit_reference( Character.name_ref, strings )
    vertices : vector< Character >; }"#;
            pub const EDGES: &str = r#"namespace coappearances { /**
 * An appearance of two characters in the same scene.
 *
 * count - multiplicity of the coappearance.
 * first_chapter_ref - a reference to the first chapter in which characters appear. How to get the
 * full range of chapters is described in 'coappearances.cpp:read'.
 */
struct Coappearance {
    a_ref : u32 : 16;
    b_ref : u32 : 16;
    count : u32 : 16;
    first_chapter_ref: u32 : 16;
} }
namespace coappearances { @explicit_reference( Coappearance.a_ref, vertices )
    @explicit_reference( Coappearance.b_ref, vertices )
    @explicit_reference( Coappearance.first_chapter_ref, chapters )
    edges : vector< Coappearance >; }"#;
            pub const VERTICES_DATA: &str = r#"namespace coappearances { /**
 * A nickname or an alternative name of a character.
 */
struct Nickname {
    ref: u32 : 32;
} }
namespace coappearances { /**
 * A description of a character.
 */
struct Description {
    ref: u32 : 32;
} }
namespace coappearances { /**
 * A relation of a character to another one.
 */
struct UnaryRelation {
    kind_ref: u32 : 32;
    to_ref: u32 : 16;
} }
namespace coappearances { /**
 * A relation of a character to two other characters.
 */
struct BinaryRelation {
    kind_ref: u32 : 32;
    to_a_ref: u32 : 16;
    to_b_ref: u32 : 16;
} }
namespace _builtin.multivector { struct IndexType32 { value : u64 : 32; } }
namespace coappearances { @explicit_reference( Nickname.ref, strings )
    @explicit_reference( Description.ref, strings )
    @explicit_reference( UnaryRelation.kind_ref, strings )
    @explicit_reference( UnaryRelation.to_ref, vertices )
    @explicit_reference( BinaryRelation.kind_ref, strings )
    @explicit_reference( BinaryRelation.to_a_ref, vertices )
    @explicit_reference( BinaryRelation.to_b_ref, vertices )
    vertices_data: multivector< 32, Nickname, Description, UnaryRelation, BinaryRelation >; }"#;
            pub const CHAPTERS: &str = r#"namespace coappearances { /**
 * A chapter in the book.
 */
struct Chapter {
    major: u8 : 4;
    minor: u8 : 7;
} }
namespace coappearances { chapters : vector< Chapter >; }"#;
            pub const STRINGS: &str = r#"namespace coappearances { // All strings contained in the data separated by '\0'.
    strings: raw_data; }"#;
            pub const STATISTICS: &str = r#"namespace coappearances { @bound_implicitly( characters: Graph.vertices, vertex_degrees )
archive Statistics {
    invariants : Invariants;

    // indexed by `vertices`
    vertex_degrees : vector< Degree >;
} }
namespace coappearances { struct Invariants {
    max_degree : u32 : 16;
    max_degree_ref : u32 : 16;
    min_degree : u32 : 16;
    min_degree_ref : u32 : 16;
    num_connected_components : u32 : 16;
} }
namespace coappearances { struct Degree {
    value : u32 : 16;
} }
namespace coappearances { // Optional archive containing calculated statistics.
    @optional
    statistics : archive Statistics; }"#;
            pub const CHARACTERS: &str = r#"namespace coappearances { None }"#;
        }
    }
}

/// Builtin type to for MultiVector index
define_index!(
    IndexType32,
    IndexType32Mut,
    schema::structs::INDEX_TYPE32,
    4,
    32
);

define_struct!(
    Degree,
    DegreeMut,
    schema::structs::DEGREE,
    2,
    (value, set_value, u32, 0, 16)
);

define_struct!(
    Invariants,
    InvariantsMut,
    schema::structs::INVARIANTS,
    10,
    (max_degree, set_max_degree, u32, 0, 16),
    (max_degree_ref, set_max_degree_ref, u32, 16, 16),
    (min_degree, set_min_degree, u32, 32, 16),
    (min_degree_ref, set_min_degree_ref, u32, 48, 16),
    (
        num_connected_components,
        set_num_connected_components,
        u32,
        64,
        16
    )
);

define_archive!(Statistics, StatisticsBuilder,
    schema::structs::STATISTICS;
    // struct resources
    (invariants, set_invariants,
        Invariants, schema::resources::statistics::INVARIANTS, false);
    // vector resources
    (vertex_degrees, set_vertex_degrees, start_vertex_degrees,
        Degree, schema::resources::statistics::VERTEX_DEGREES, false);
    // multivector resources
;
    // raw data resources
;
    // subarchives
);

/// A chapter in the book.
define_struct!(
    Chapter,
    ChapterMut,
    schema::structs::CHAPTER,
    2,
    (major, set_major, u8, 0, 4),
    (minor, set_minor, u8, 4, 7)
);

/// A relation of a character to two other characters.
define_struct!(
    BinaryRelation,
    BinaryRelationMut,
    schema::structs::BINARY_RELATION,
    8,
    (kind_ref, set_kind_ref, u32, 0, 32),
    (to_a_ref, set_to_a_ref, u32, 32, 16),
    (to_b_ref, set_to_b_ref, u32, 48, 16)
);

/// A relation of a character to another one.
define_struct!(
    UnaryRelation,
    UnaryRelationMut,
    schema::structs::UNARY_RELATION,
    6,
    (kind_ref, set_kind_ref, u32, 0, 32),
    (to_ref, set_to_ref, u32, 32, 16)
);

/// A description of a character.
define_struct!(
    Description,
    DescriptionMut,
    schema::structs::DESCRIPTION,
    4,
    (ref_, set_ref, u32, 0, 32)
);

/// A nickname or an alternative name of a character.
define_struct!(
    Nickname,
    NicknameMut,
    schema::structs::NICKNAME,
    4,
    (ref_, set_ref, u32, 0, 32)
);

/// An appearance of two characters in the same scene.
///
/// count - multiplicity of the coappearance.
/// first_chapter_ref - a reference to the first chapter in which characters
/// appear. How to get the full range of chapters is described in
/// 'coappearances.cpp:read'.
define_struct!(
    Coappearance,
    CoappearanceMut,
    schema::structs::COAPPEARANCE,
    8,
    (a_ref, set_a_ref, u32, 0, 16),
    (b_ref, set_b_ref, u32, 16, 16),
    (count, set_count, u32, 32, 16),
    (first_chapter_ref, set_first_chapter_ref, u32, 48, 16)
);

/// A character.
define_struct!(
    Character,
    CharacterMut,
    schema::structs::CHARACTER,
    4,
    (name_ref, set_name_ref, u32, 0, 32)
);

/// Meta information about the book.
define_struct!(
    Meta,
    MetaMut,
    schema::structs::META,
    8,
    (title_ref, set_title_ref, u32, 0, 32),
    (author_ref, set_author_ref, u32, 32, 32)
);

/// Builtin union type of Nickname, Description, UnaryRelation, BinaryRelation.
define_variadic_struct!(VerticesData, VerticesDataItemBuilder,
    IndexType32,
    0 => (Nickname, add_nickname),
    1 => (Description, add_description),
    2 => (UnaryRelation, add_unary_relation),
    3 => (BinaryRelation, add_binary_relation));

define_archive!(Graph, GraphBuilder,
    schema::structs::GRAPH;
    // struct resources
    (meta, set_meta,
        Meta, schema::resources::graph::META, false);
    // vector resources
    (vertices, set_vertices, start_vertices,
        Character, schema::resources::graph::VERTICES, false),
    (edges, set_edges, start_edges,
        Coappearance, schema::resources::graph::EDGES, false),
    (chapters, set_chapters, start_chapters,
        Chapter, schema::resources::graph::CHAPTERS, false);
    // multivector resources
    (vertices_data, start_vertices_data,
        VerticesData, schema::resources::graph::VERTICES_DATA,
        vertices_data_index, IndexType32, false);
    // raw data resources
    (strings, set_strings,
        schema::resources::graph::STRINGS, false);
    // subarchives
    (statistics,
        Statistics, StatisticsBuilder,
        schema::resources::graph::STATISTICS, true));