donet_core/dcmolecular.rs
1/*
2 This file is part of Donet.
3
4 Copyright © 2024 Max Rodriguez <[email protected]>
5
6 Donet is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Affero General Public License,
8 as published by the Free Software Foundation, either version 3
9 of the License, or (at your option) any later version.
10
11 Donet is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with Donet. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20//! Data model for a DC Molecular field, which represents
21//! a form of a field 'alias' for a collection of fields.
22
23use crate::dcatomic::DCAtomicField;
24use crate::dcfield::DCField;
25use crate::hashgen::*;
26
27/// An abstract field which provides an interface to access
28/// multiple atomic fields under one field and one identifier.
29#[derive(Debug)]
30pub struct DCMolecularField<'dc> {
31 base_field: DCField<'dc>,
32 atomic_fields: Vec<&'dc DCAtomicField<'dc>>,
33}
34
35impl std::fmt::Display for DCMolecularField<'_> {
36 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
37 writeln!(f, "TODO")
38 }
39}
40
41impl LegacyDCHash for DCMolecularField<'_> {
42 fn generate_hash(&self, hashgen: &mut DCHashGenerator) {
43 self.base_field.generate_hash(hashgen);
44
45 hashgen.add_int(self.atomic_fields.len().try_into().unwrap());
46
47 for atomic in &self.atomic_fields {
48 atomic.generate_hash(hashgen);
49 }
50 }
51}
52
53impl<'dc> DCMolecularField<'dc> {
54 #[inline(always)]
55 pub fn get_num_atomics(&self) -> usize {
56 self.atomic_fields.len()
57 }
58
59 #[inline(always)]
60 pub fn get_atomic_field(&self, index: usize) -> Option<&'dc DCAtomicField> {
61 self.atomic_fields.get(index).copied()
62 }
63}