json_ld_core/document/
flattened.rs

1use rdf_types::{Generator, Vocabulary};
2
3use crate::{IdentifyAll, IndexedNode, Relabel};
4use std::{collections::HashSet, hash::Hash};
5
6/// Result of the document flattening algorithm.
7///
8/// It is just an alias for a set of (indexed) nodes.
9pub type FlattenedDocument<T, B> = Vec<IndexedNode<T, B>>;
10
11impl<T, B> IdentifyAll<T, B> for FlattenedDocument<T, B> {
12	#[inline(always)]
13	fn identify_all_with<V: Vocabulary<Iri = T, BlankId = B>, G: Generator<V>>(
14		&mut self,
15		vocabulary: &mut V,
16		generator: &mut G,
17	) where
18		T: Eq + Hash,
19		B: Eq + Hash,
20	{
21		for node in self {
22			node.identify_all_with(vocabulary, generator)
23		}
24	}
25}
26
27impl<T, B> Relabel<T, B> for FlattenedDocument<T, B> {
28	fn relabel_with<N: Vocabulary<Iri = T, BlankId = B>, G: Generator<N>>(
29		&mut self,
30		vocabulary: &mut N,
31		generator: &mut G,
32		relabeling: &mut hashbrown::HashMap<B, rdf_types::Subject<T, B>>,
33	) where
34		T: Clone + Eq + Hash,
35		B: Clone + Eq + Hash,
36	{
37		for node in self {
38			node.relabel_with(vocabulary, generator, relabeling)
39		}
40	}
41}
42
43pub type UnorderedFlattenedDocument<T, B> = HashSet<IndexedNode<T, B>>;