MCPcopy Create free account
hub / github.com/cosdata/cosdata / new

Method new

src/metadata/schema.rs:87–111  ·  view source on GitHub ↗

Constructor for MetadataField Also checks that all FieldValue's are of the same variant

(name: String, values: HashSet<FieldValue>)

Source from the content-addressed store, hash-verified

85 ///
86 /// Also checks that all FieldValue's are of the same variant
87 pub fn new(name: String, values: HashSet<FieldValue>) -> Result<Self, Error> {
88 // validate input
89 let unique_types = values
90 .iter()
91 .map(|value| value.type_as_str())
92 .collect::<HashSet<&str>>();
93 if unique_types.len() > 1 {
94 return Err(Error::InvalidFieldValues(
95 "Field values must be homogeneous in type".to_owned(),
96 ));
97 }
98 let value_index = set_to_value_index(values);
99 let cardinality = value_index.len();
100 // @NOTE: No. of dimensions are calculated to support 1 value
101 // more than the cardinality because the index in value_index
102 // starts with 1 and not 0. In other words, 0 is not used to
103 // represent any value.
104 let num_dims = nearest_power_of_two((cardinality + 1) as u16)
105 .ok_or(Error::InvalidFieldCardinality(format!("Field = {name}")))?;
106 Ok(Self {
107 name,
108 value_index,
109 num_dims,
110 })
111 }
112
113 /// Returns a numeric identifier for the value from the `value_index`
114 pub fn value_id(&self, value: &FieldValue) -> Result<u16, Error> {

Callers

nothing calls this directly

Calls 11

set_to_value_indexFunction · 0.85
nearest_power_of_twoFunction · 0.85
type_as_strMethod · 0.80
field_namesMethod · 0.80
comparable_encodingMethod · 0.80
containsMethod · 0.80
cloneMethod · 0.80
iterMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected