MCPcopy Create free account
hub / github.com/ablab/spades / deserialize_impl

Method deserialize_impl

ext/include/tsl/array-hash/array_hash.h:1653–1727  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1651
1652 template <class Deserializer>
1653 void deserialize_impl(Deserializer& deserializer, bool hash_compatible) {
1654 tsl_ah_assert(m_buckets_data.empty()); // Current hash table must be empty
1655
1656 const slz_size_type version =
1657 deserialize_value<slz_size_type>(deserializer);
1658 // For now we only have one version of the serialization protocol.
1659 // If it doesn't match there is a problem with the file.
1660 if (version != SERIALIZATION_PROTOCOL_VERSION) {
1661 throw std::runtime_error(
1662 "Can't deserialize the array_map/set. The protocol version header is "
1663 "invalid.");
1664 }
1665
1666 const slz_size_type bucket_count_ds =
1667 deserialize_value<slz_size_type>(deserializer);
1668 const slz_size_type nb_elements =
1669 deserialize_value<slz_size_type>(deserializer);
1670 const float max_load_factor = deserialize_value<float>(deserializer);
1671
1672 m_nb_elements = numeric_cast<IndexSizeT>(
1673 nb_elements, "Deserialized nb_elements is too big.");
1674
1675 size_type bucket_count = numeric_cast<size_type>(
1676 bucket_count_ds, "Deserialized bucket_count is too big.");
1677 GrowthPolicy::operator=(GrowthPolicy(bucket_count));
1678
1679 this->max_load_factor(max_load_factor);
1680 value_container<T>::reserve(m_nb_elements);
1681
1682 if (hash_compatible) {
1683 if (bucket_count != bucket_count_ds) {
1684 throw std::runtime_error(
1685 "The GrowthPolicy is not the same even though hash_compatible is "
1686 "true.");
1687 }
1688
1689 m_buckets_data.reserve(bucket_count);
1690 for (size_type i = 0; i < bucket_count; i++) {
1691 m_buckets_data.push_back(array_bucket::deserialize(deserializer));
1692 deserialize_bucket_values(deserializer, m_buckets_data.back());
1693 }
1694 } else {
1695 m_buckets_data.resize(bucket_count);
1696 for (size_type i = 0; i < bucket_count; i++) {
1697 // TODO use buffer to avoid reallocation on each deserialization.
1698 array_bucket bucket = array_bucket::deserialize(deserializer);
1699 deserialize_bucket_values(deserializer, bucket);
1700
1701 for (auto it_val = bucket.cbegin(); it_val != bucket.cend(); ++it_val) {
1702 const std::size_t ibucket =
1703 bucket_for_hash(hash_key(it_val.key(), it_val.key_size()));
1704
1705 auto it_find = m_buckets_data[ibucket].find_or_end_of_bucket(
1706 it_val.key(), it_val.key_size());
1707 if (it_find.second) {
1708 throw std::runtime_error(
1709 "Error on deserialization, the same key is presents multiple "
1710 "times.");

Callers

nothing calls this directly

Calls 13

max_load_factorMethod · 0.95
find_or_end_of_bucketMethod · 0.80
deserializeFunction · 0.50
emptyMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45
backMethod · 0.45
resizeMethod · 0.45
cbeginMethod · 0.45
cendMethod · 0.45
keyMethod · 0.45
key_sizeMethod · 0.45

Tested by

no test coverage detected