Lightweight tagged data library.
1#![allow(dead_code)]
2
3use crate::{label::Label, parse::Parser, tag::Tag, TagManager};
4use std::{collections::BTreeMap, hash::BuildHasher, marker::PhantomData};
5use string_interner::backend::Backend as InternerBackend;
6use string_interner::Symbol;
7
8struct QueryBuilder<'m, L, S, T, P, B, H>
9where
10 L: Label,
11 S: Symbol,
12 T: Tag<Label = L, Symbol = S>,
13 P: Parser<Tag = T> + Send + Sync,
14 B: InternerBackend<Symbol = S>,
15 H: BuildHasher,
16{
17 manager: &'m TagManager<L, S, T, P, B, H>,
18 indices: QueryIndices<S>,
19}
20
21struct QueryIndices<S>
22where
23 S: Symbol,
24{
25 plain: PlainIndex<S>,
26 key_value: KeyValueIndex<S>,
27 multipart: MultipartIndex<S>,
28}
29
30struct PlainIndex<S>(Vec<S>)
31where
32 S: Symbol;
33
34struct KeyValueIndex<S>(BTreeMap<S, Vec<S>>)
35where
36 S: Symbol;
37
38struct MultipartIndex<S>(Vec<Trie<S>>)
39where
40 S: Symbol;
41
42struct Trie<S>(PhantomData<S>)
43where
44 S: Symbol;
45
46/*
47The basic design of the query system is:
48
49manager
50 .select_from(&container_of_queryable_things)
51 .where(Contains(And("this-tag", Or("that_tag", "someothertag"))))
52 .run()
53
54
55This isn't the exact API, because it needs to have a way to resolve
56the query tags such that identity-based matching can happen.
57
58When it's doing the "select_from" construction, it needs to go through the
59queryable-things and construct indices of their tags.
60
61
62Individual queries probably need to be relative to a single tag manager,
63to be able to match up the parser and storage.
64
65But then those queries return iterators over tagged items, and the
66intersection of the returned items from multiple queries is the answer
67to all the queries.
68
69
70struct QueryEngine {
71 indices: QueryIndices,
72}
73
74struct QueryIndices {
75 plain_index: PlainIndex,
76 key_value_index: KeyValueIndex,
77 multipart_index: MultipartIndex,
78}
79
80/*
81 Queries might include:
82 - Find all items with this tag and that tag but not that tag
83 - Find all items with tags starting with this path
84 - Find all items with this key for key-value
85 - Find all items with this key and a value matching some constraint
86 - Specific value
87 - Set of values
88 - Values match regex
89 - Values are parseable into a particular type
90 - Values parseable into a type meet some constraint on that type
91
92 */
93
94// This will just be a sorted vector.
95struct PlainIndex {
96
97}
98
99// This one will be a hash map, with keys being the keys of all KV tags, and values being sorted vectors of values.
100struct KeyValueIndex {
101
102}
103
104// This one will be a forest, a set of trees with roots being all the first segments of multipart paths.
105struct MultipartIndex {
106
107}
108*/