Sample Set Management#
SampleSet#
-
class ReadOnlySampleSet#
ReadOnlySampleSet is a read-only database to store list of samples. User can query the samples by using the iterator or the index.
See also
Subclassed by aidi::SampleSet
Public Functions
-
bool exists(uint32_t id) const#
Check If the ID is exists in the sample set.
- Parameters:
id – sample id
- Returns:
true
- Returns:
false
-
size_t size() const#
Get sample count of the sample set.
Warning
This operation is expensive as it needs to iterate all samples, so it is not recommended to use it in a loop or in a performance critical path.
- Returns:
size_t sample count.
-
Sample get(uint32_t id) const#
Get sample corresponding to the ID.
- Parameters:
id – sample id
- Throws:
aidi::excepts::SampleNotFound – Sample with the input id does exists in the sample set.
- Returns:
-
SampleSetIterator begin() const#
Get sample set iterator handle of pointing to the first sample.
- Throws:
aidi::excepts::SampleNotFound – Failed to seek iterator to the first sample in the sample set. maybe the sample set is empty.
- Returns:
SampleSetIterator pointing to the first sample.
-
SampleSetIterator at(uint32_t id) const#
Get sample set iterator handle of pointing to the corresponding sample of the ID.
- Parameters:
id – sample id.
- Throws:
aidi::excepts::SampleNotFound – Failed to seek iterator to the sample with the input id in the sample set. maybe the sample does not exist.
- Returns:
SampleSetIterator pointing to the corresponding sample of the ID.
-
SampleSetIterator end() const#
Get sample set iterator handle of pointing to the last sample.
- Throws:
aidi::excepts::SampleNotFound – Failed to seek iterator to the last sample in the sample set. maybe the sample set is empty.
- Returns:
SampleSetIterator pointing to the last sample.
-
ReadOnlyPropertySet readonly_property_set(const std::string &property_name) const#
Get read only property set handle.
Note
The ReadOnlyPropertySet handle is dependent on the sample set, so it should not be used after the sample set is closed.
- Throws:
aidi::excepts::SampleNotFound – The input property name is not found.
- Returns:
ReadOnlyPropertySet The read only property set handle.
-
bool exists(uint32_t id) const#
-
class SampleSet : public aidi::ReadOnlySampleSet#
SampleSet is a database to store list of samples. User can add, remove or modify the samples in the sample set.
See also
Public Functions
-
uint32_t add_empty_sample()#
Create a empty sample and add it to the sample set, return the ID of the sample and the sample handle.
- Throws:
aidi::excepts::RocksDBError – Get or Put counter_max_id failed.
- Returns:
uint32_t The Sample ID and sample handle.
-
uint32_t add(const Sample &data)#
Store the input sample into the sample set and return the ID.
- Parameters:
data – sample
- Throws:
aidi::excepts::PropertyTypeMismatch – Some property names and types in the input sample is not equl the sample set.
aidi::excepts::RocksDBError – Failed to get new sample id.
- Returns:
uint32_t sample id.
-
void update(uint32_t id, const Sample &data)#
Update all data of the ID in the sample set to the input sample, the existing property will be overwritten.
Note
If some properties in the input sample are empty, they will not be updated.
- Throws:
aidi::excepts::SampleNotFound – Sample with the input id does not exist in the sample set.
aidi::excepts::PropertyTypeMismatch – Some property names and types in the input sample is not equl the sample set.
- Parameters:
id – sample id.
data –
-
void update(const SampleSetIterator &iter, const Sample &data)#
Update all data of the iterator in the sample set to the input sample, the existing property will be overwritten.
- Throws:
aidi::excepts::InvalidIterator – The input iterator is invalid.
- Parameters:
iter – sample set iterator handle.
data –
-
void erase(uint32_t id)#
Delete all data of this ID in the sample set.
- Throws:
aidi::excepts::SampleNotFound – Sample with the input id does not exist in the sample set.
aidi::excepts::RocksDBError – delete some one property failed.
- Parameters:
id – sample id.
-
SampleSetIterator erase(const SampleSetIterator &iter)#
Delete all data of this iterator in the sample set, and return the iterator pointing to the next sample.
Note
If hte input iterator pointing to last sample, return iterator is invalid (ret_iter.valid() = false).
- Parameters:
iter – sample set iterator handle.
- Throws:
aidi::excepts::InvalidIterator – The input iterator is invalid.
- Returns:
-
PropertySet property_set(const std::string &property_name)#
Get property set handle.
Note
The PropertySet handle is dependent on the sample set, so it should not be used after the sample set is closed.
- Throws:
aidi::excepts::SampleNotFound – The input property name is not found.
- Returns:
PropertySet The property set handle.
-
uint32_t add_empty_sample()#
-
class SampleSetIterator#
SampleSetIterator is a iterator to iterate all samples in the sample set.
See also
Public Functions
-
SampleSetIterator &operator++()#
iterator pointing to next sample.
- Attention
The iterator must be valid.
- Returns:
-
SampleSetIterator &operator--()#
iterator pointing to prev sample.
- Attention
The iterator must be valid.
- Returns:
-
SampleSetIterator operator++(int)#
return separate copy of the current iterator, and iterator pointing to next sample.
- Attention
The iterator must be valid.
- Returns:
SampleSetIterator separate copy of the current iterator.
-
SampleSetIterator operator--(int)#
return separate copy of the current iterator, and iterator pointing to prev sample.
- Attention
The iterator must be valid.
- Returns:
SampleSetIterator separate copy of the current iterator.
-
void seek_to_first()#
Set Iterator to the first sample.
-
void seek_to(uint32_t id)#
Set Iterator to the sample with the given id.
- Parameters:
id – The id of the sample.
-
void seek_to_last()#
Set Iterator to the last sample.
-
bool operator!=(const SampleSetIterator &other) const#
Judge whether two iterators pointing to the different sample.
- Attention
The iterator must be valid.
- Parameters:
other –
- Returns:
true
- Returns:
false
-
bool operator==(const SampleSetIterator &other) const#
Judge whether two iterators pointing to the same sample.
- Attention
The iterator must be valid.
- Parameters:
other –
- Returns:
true
- Returns:
false
-
Sample operator*() const#
Get sample of corresponding to the current iterator.
- Attention
The iterator must be valid.
- Returns:
-
bool valid() const#
Check if the iterator is valid.
- Attention
Make sure the iterator is valid before calling the operation of the iterator.
- Returns:
true
- Returns:
false
-
uint32_t id() const#
Get the ID of the sample pointing to by the current iterator.
- Attention
The iterator must be valid.
- Throws:
aidi::excepts::InvalidIterator – The iterator is invalid.
- Returns:
uint32_t sample id of currnet iterator.
-
SampleSetIterator &operator++()#
PropertySet#
-
class ReadOnlyPropertySet#
Read-only property set.
Subclassed by aidi::PropertySet
Public Functions
-
bool sample_exists(uint32_t id) const#
Check If the ID exists in the property set.
- Parameters:
id – sample id
- Returns:
true
- Returns:
false
-
bool data_exists(uint32_t id) const#
Check If the property data to the ID exists in the property set.
- Parameters:
id – sample id
- Returns:
true
- Returns:
false
-
size_t sample_size() const#
Get sample count of the sample set.
See also
Warning
This operation is expensive as it needs to iterate all samples, so it is not recommended to use it in a loop or in a performance critical path.
- Returns:
size_t sample count.
-
std::shared_ptr<props::IProperty> get(uint32_t id) const#
Get property data pointer corresponding to the ID.
- Throws:
aidi::excepts::SampleNotFound – Failed to create iterator for property set, maybe the specified by input id does not exist.
- Parameters:
id – sample id
- Returns:
std::shared_ptr<props::IProperty> The property data specified by the input id.
- Returns:
nullptr If the input id does not exsit in the property set.
-
PropertySetIterator begin() const#
Get PropertySetIterator of pointing to the first Property.
- Throws:
aidi::excepts::SampleNotFound – Failed to seek iterator to the first property in the property set. maybe the property set is empty.
- Returns:
PropertySetIterator pointing to the first Property.
-
PropertySetIterator at(uint32_t id) const#
Get PropertySetIterator of pointing to the corresponding property of sample ID.
- Throws:
aidi::excepts::SampleNotFound – Failed to create iterator for property set, maybe the sample specified by input id does not exist.”,
- Parameters:
id – sample id
- Returns:
PropertySetIterator pointing to corresponding property of the ID.
-
PropertySetIterator end() const#
get PropertySetIterator pointing to the last Property
- Throws:
aidi::excepts::SampleNotFound – Failed to seek iterator to the last property in the property set. maybe the property set is empty.
- Returns:
PropertySetIterator pointing to the last property.
-
int64_t last_update_time() const#
Get last update time of the property set in utc timestamp.
- Returns:
int64_t The last update time of the property set in utc timestamp.
-
bool sample_exists(uint32_t id) const#
-
class PropertySet : public aidi::ReadOnlyPropertySet#
PropertySet read-write data accessor for property set.
Public Functions
-
void update(uint32_t id, const props::IProperty &property)#
Update proeprty of the ID in the property set to the input property, the existing property will be overwritten.
- Throws:
aidi::excepts::RocksDBError – the property get or put error.
aidi::excepts::SampleNotFound – Failed to seek iterator to the last property in the property set.
- Parameters:
id – sample id
property –
-
void update(const PropertySetIterator &iter, const props::IProperty &property)#
Update proeprty of the iterator in the property set to the input property, the existing property will be overwritten.
- Attention
The PropertySetIterator must be valid.
- Throws:
aidi::excepts::InvalidIterator – The input iterator is not point to a valid sample.
- Parameters:
iter – PropertySetIterator from sample set that needs to be updated
property –
-
void erase(uint32_t id)#
Delete the property of the ID from the property set.
- Throws:
aidi::excepts::SampleNotFound – Sample with the input id does not exist in the property set.
- Parameters:
id – sample id.
-
PropertySetIterator erase(const PropertySetIterator &iter)#
Delete the property of the PropertySetIterator from the property set, return iterator that points to the next property.
- Attention
The PropertySetIterator must be valid and consistent with property set.
- Attention
If iter pointing to last Property, return PropertySetIterator that is invalid.
- Throws:
aidi::excepts::InvalidIterator – The input iterator is not point to a valid sample.
- Parameters:
iter – PropertySetIterator to be deleted from property set
- Returns:
PropertySetIterator pointing to the next property.
-
void update(uint32_t id, const props::IProperty &property)#
-
class PropertySetIterator#
Iterator for the PropertySet.
Public Functions
-
PropertySetIterator(const PropertySetIterator &other)#
Construct a new property set iterator object. The iterator created is a separate copy of the source iterator.
-
PropertySetIterator &operator=(const PropertySetIterator &other)#
Only iterator of the same property set are allowed to assign values to each other, and the created iterator are independent copy of the source iterator.
- Returns:
-
PropertySetIterator &operator++()#
iterator pointing to next property.
- Attention
The iterator must be valid.
- Returns:
-
PropertySetIterator &operator--()#
iterator pointing to prev property.
- Attention
The iterator must be valid.
- Returns:
-
PropertySetIterator operator++(int)#
return separate copy of the current iterator, and iterator pointing to next property.
- Attention
The iterator must be valid.
- Returns:
PropertySetIterator separate copy of the current iterator.
-
PropertySetIterator operator--(int)#
return separate copy of the current iterator, and iterator pointing to prev Property.
- Attention
The iterator must be valid.
- Returns:
-
std::shared_ptr<props::IProperty> operator*() const#
Get property of corresponding to the current iterator.
- Returns:
std::shared_ptr<props::IProperty>
-
void seek_to_first()#
Set Iterator to the first sample.
-
void seek_to(uint32_t id)#
Set Iterator to the sample with the given id.
- Parameters:
id – The id of the sample.
-
void seek_to_last()#
Set Iterator to the last sample.
-
bool operator!=(const PropertySetIterator &other) const#
Judge whether two iterators pointing to the different property.
- Parameters:
other – The other iterator.
- Returns:
true if two iterators pointing to the different property.
- Returns:
false if two iterators pointing to the same property.
-
bool operator==(const PropertySetIterator &other) const#
Judge whether two iterators pointing to the same property.
- Parameters:
other – The other iterator.
- Returns:
true if two iterators pointing to the same property.
- Returns:
false if two iterators pointing to the different property.
-
bool valid() const#
Check if the iterator is valid.
- Attention
Make sure the iterator is valid before calling the operation of the iterator.
- Returns:
true if the iterator is valid.
- Returns:
false if the iterator is invalid.
-
uint32_t id() const#
Get the ID of the property pointing to by the current iterator.
- Attention
The iterator must be valid.
- Throws:
aidi::excepts::InvalidIterator – The iterator is invalid.
- Returns:
uint32_t sample id of currnet iterator.
-
std::shared_ptr<props::IProperty> get() const#
Get Property of corresponding to the current iterator.
- Throws:
aidi::excepts::InvalidIterator – The iterator is invalid.
- Returns:
std::shared_ptr<props::IProperty> Property data of currnet iterator. It will be nullptr if the sample exists but the property data is not set.
-
PropertySetIterator(const PropertySetIterator &other)#