flatdata 0.2.1

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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
// Do not edit: This code was generated by flatdata's generator.


pub mod schema {
    pub mod structs {
        pub const META: &str = r#"namespace coappearances {
struct Meta
{
    title_ref : u32 : 32;
    author_ref : u32 : 32;
}
}

"#;
        pub const CHARACTER: &str = r#"namespace coappearances {
struct Character
{
    name_ref : u32 : 32;
}
}

"#;
        pub const COAPPEARANCE: &str = r#"namespace coappearances {
struct Coappearance
{
    a_ref : u32 : 16;
    b_ref : u32 : 16;
    count : u32 : 16;
    first_chapter_ref : u32 : 16;
}
}

"#;
        pub const NICKNAME: &str = r#"namespace coappearances {
struct Nickname
{
    ref : u32 : 32;
}
}

"#;
        pub const DESCRIPTION: &str = r#"namespace coappearances {
struct Description
{
    ref : u32 : 32;
}
}

"#;
        pub const UNARY_RELATION: &str = r#"namespace coappearances {
struct UnaryRelation
{
    kind_ref : u32 : 32;
    to_ref : u32 : 16;
}
}

"#;
        pub const BINARY_RELATION: &str = r#"namespace coappearances {
struct BinaryRelation
{
    kind_ref : u32 : 32;
    to_a_ref : u32 : 16;
    to_b_ref : u32 : 16;
}
}

"#;
        pub const CHAPTER: &str = r#"namespace coappearances {
struct Chapter
{
    major : u8 : 4;
    minor : u8 : 7;
}
}

"#;
        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 DEGREE: &str = r#"namespace coappearances {
struct Degree
{
    value : u32 : 16;
}
}

"#;
        pub const INDEX_TYPE32: &str = r#""#;
        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 : .coappearances.Graph.vertices, .coappearances.Statistics.vertex_degrees )
archive Statistics
{
    invariants : .coappearances.Invariants;
    vertex_degrees : vector< .coappearances.Degree >;
}
}

"#;
        pub const GRAPH: &str = r#"namespace coappearances {
struct Meta
{
    title_ref : u32 : 32;
    author_ref : u32 : 32;
}
}

namespace coappearances {
struct Character
{
    name_ref : u32 : 32;
}
}

namespace coappearances {
struct Coappearance
{
    a_ref : u32 : 16;
    b_ref : u32 : 16;
    count : u32 : 16;
    first_chapter_ref : u32 : 16;
}
}

namespace coappearances {
struct Nickname
{
    ref : u32 : 32;
}
}

namespace coappearances {
struct Description
{
    ref : u32 : 32;
}
}

namespace coappearances {
struct UnaryRelation
{
    kind_ref : u32 : 32;
    to_ref : u32 : 16;
}
}

namespace coappearances {
struct BinaryRelation
{
    kind_ref : u32 : 32;
    to_a_ref : u32 : 16;
    to_b_ref : u32 : 16;
}
}

namespace coappearances {
struct Chapter
{
    major : u8 : 4;
    minor : u8 : 7;
}
}

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 : .coappearances.Graph.vertices, .coappearances.Statistics.vertex_degrees )
archive Statistics
{
    invariants : .coappearances.Invariants;
    vertex_degrees : vector< .coappearances.Degree >;
}
}

namespace coappearances {
@bound_implicitly( characters : .coappearances.Graph.vertices, .coappearances.Graph.vertices_data )
archive Graph
{
    @explicit_reference( .coappearances.Meta.title_ref, .coappearances.Graph.strings )
    @explicit_reference( .coappearances.Meta.author_ref, .coappearances.Graph.strings )
    meta : .coappearances.Meta;
    @explicit_reference( .coappearances.Character.name_ref, .coappearances.Graph.strings )
    vertices : vector< .coappearances.Character >;
    @explicit_reference( .coappearances.Coappearance.a_ref, .coappearances.Graph.vertices )
    @explicit_reference( .coappearances.Coappearance.b_ref, .coappearances.Graph.vertices )
    @explicit_reference( .coappearances.Coappearance.first_chapter_ref, .coappearances.Graph.chapters )
    edges : vector< .coappearances.Coappearance >;
    @explicit_reference( .coappearances.Nickname.ref, .coappearances.Graph.strings )
    @explicit_reference( .coappearances.Description.ref, .coappearances.Graph.strings )
    @explicit_reference( .coappearances.UnaryRelation.kind_ref, .coappearances.Graph.strings )
    @explicit_reference( .coappearances.UnaryRelation.to_ref, .coappearances.Graph.vertices )
    @explicit_reference( .coappearances.BinaryRelation.kind_ref, .coappearances.Graph.strings )
    @explicit_reference( .coappearances.BinaryRelation.to_a_ref, .coappearances.Graph.vertices )
    @explicit_reference( .coappearances.BinaryRelation.to_b_ref, .coappearances.Graph.vertices )
    vertices_data : multivector< 32, .coappearances.Nickname, .coappearances.Description, .coappearances.UnaryRelation, .coappearances.BinaryRelation >;
    chapters : vector< .coappearances.Chapter >;
    strings : raw_data;
    @optional
    statistics : archive .coappearances.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 {
archive Statistics
{
    invariants : .coappearances.Invariants;
}
}

"#;
pub const VERTEX_DEGREES: &str = r#"namespace coappearances {
struct Degree
{
    value : u32 : 16;
}
}

namespace coappearances {
archive Statistics
{
    vertex_degrees : vector< .coappearances.Degree >;
}
}

"#;
pub const CHARACTERS: &str = r#"namespace coappearances {
@bound_implicitly( characters : .coappearances.Graph.vertices, .coappearances.Statistics.vertex_degrees )
archive Statistics
{
}
}

"#;
        }
        pub mod graph {
pub const META: &str = r#"namespace coappearances {
struct Meta
{
    title_ref : u32 : 32;
    author_ref : u32 : 32;
}
}

namespace coappearances {
archive Graph
{
    @explicit_reference( .coappearances.Meta.title_ref, .coappearances.Graph.strings )
    @explicit_reference( .coappearances.Meta.author_ref, .coappearances.Graph.strings )
    meta : .coappearances.Meta;
}
}

"#;
pub const VERTICES: &str = r#"namespace coappearances {
struct Character
{
    name_ref : u32 : 32;
}
}

namespace coappearances {
archive Graph
{
    @explicit_reference( .coappearances.Character.name_ref, .coappearances.Graph.strings )
    vertices : vector< .coappearances.Character >;
}
}

"#;
pub const EDGES: &str = r#"namespace coappearances {
struct Coappearance
{
    a_ref : u32 : 16;
    b_ref : u32 : 16;
    count : u32 : 16;
    first_chapter_ref : u32 : 16;
}
}

namespace coappearances {
archive Graph
{
    @explicit_reference( .coappearances.Coappearance.a_ref, .coappearances.Graph.vertices )
    @explicit_reference( .coappearances.Coappearance.b_ref, .coappearances.Graph.vertices )
    @explicit_reference( .coappearances.Coappearance.first_chapter_ref, .coappearances.Graph.chapters )
    edges : vector< .coappearances.Coappearance >;
}
}

"#;
pub const VERTICES_DATA: &str = r#"namespace coappearances {
struct Nickname
{
    ref : u32 : 32;
}
}

namespace coappearances {
struct Description
{
    ref : u32 : 32;
}
}

namespace coappearances {
struct UnaryRelation
{
    kind_ref : u32 : 32;
    to_ref : u32 : 16;
}
}

namespace coappearances {
struct BinaryRelation
{
    kind_ref : u32 : 32;
    to_a_ref : u32 : 16;
    to_b_ref : u32 : 16;
}
}

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

"#;
pub const CHAPTERS: &str = r#"namespace coappearances {
struct Chapter
{
    major : u8 : 4;
    minor : u8 : 7;
}
}

namespace coappearances {
archive Graph
{
    chapters : vector< .coappearances.Chapter >;
}
}

"#;
pub const STRINGS: &str = r#"namespace coappearances {
archive Graph
{
    strings : raw_data;
}
}

"#;
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 : .coappearances.Graph.vertices, .coappearances.Statistics.vertex_degrees )
archive Statistics
{
    invariants : .coappearances.Invariants;
    vertex_degrees : vector< .coappearances.Degree >;
}
}

namespace coappearances {
archive Graph
{
    @optional
    statistics : archive .coappearances.Statistics;
}
}

"#;
pub const CHARACTERS: &str = r#"namespace coappearances {
@bound_implicitly( characters : .coappearances.Graph.vertices, .coappearances.Graph.vertices_data )
archive Graph
{
}
}

"#;
        }
    }
}

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

/// A character.
define_struct!(
    Character,
    RefCharacter,
    RefMutCharacter,
    schema::structs::CHARACTER,
    4,
    (name_ref, set_name_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,
    RefCoappearance,
    RefMutCoappearance,
    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 nickname or an alternative name of a character.
define_struct!(
    Nickname,
    RefNickname,
    RefMutNickname,
    schema::structs::NICKNAME,
    4,
    (ref_, set_ref, u32, 0, 32));

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

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

/// A relation of a character to two other characters.
define_struct!(
    BinaryRelation,
    RefBinaryRelation,
    RefMutBinaryRelation,
    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 chapter in the book.
define_struct!(
    Chapter,
    RefChapter,
    RefMutChapter,
    schema::structs::CHAPTER,
    2,
    (major, set_major, u8, 0, 4),
    (minor, set_minor, u8, 4, 7));


define_struct!(
    Invariants,
    RefInvariants,
    RefMutInvariants,
    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_struct!(
    Degree,
    RefDegree,
    RefMutDegree,
    schema::structs::DEGREE,
    2,
    (value, set_value, u32, 0, 16));

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



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
);


/// Builtin union type of Nickname, Description, UnaryRelation, BinaryRelation.
define_variadic_struct!(VerticesData, RefVerticesData, BuilderVerticesData,
    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));