reductionml_core/
global_config.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use serde_default::DefaultFromSerde;
4
5use crate::interactions::Interaction;
6
7#[derive(Serialize, Deserialize, Debug, JsonSchema, DefaultFromSerde)]
8#[serde(rename_all = "camelCase")]
9#[serde(deny_unknown_fields)]
10pub struct GlobalConfig {
11    #[serde(default = "default_num_bits")]
12    num_bits: u8,
13
14    #[serde(default)]
15    hash_seed: u32,
16
17    #[serde(default = "default_true")]
18    constant_feature_enabled: bool,
19
20    #[serde(default)]
21    interactions: Vec<Interaction>,
22}
23
24fn default_num_bits() -> u8 {
25    18
26}
27
28fn default_true() -> bool {
29    true
30}
31
32impl GlobalConfig {
33    pub fn new(
34        num_bits: u8,
35        hash_seed: u32,
36        constant_feature_enabled: bool,
37        interactions: &[Interaction],
38    ) -> GlobalConfig {
39        GlobalConfig {
40            num_bits,
41            hash_seed,
42            constant_feature_enabled,
43            interactions: interactions.to_vec(),
44        }
45    }
46
47    pub fn num_bits(&self) -> u8 {
48        self.num_bits
49    }
50
51    pub fn hash_seed(&self) -> u32 {
52        self.hash_seed
53    }
54
55    pub fn constant_feature_enabled(&self) -> bool {
56        self.constant_feature_enabled
57    }
58
59    pub fn interactions(&self) -> &[Interaction] {
60        &self.interactions
61    }
62}