/**************************************************//**
@file ha/ha0storage.cc
Hash storage.
Provides a data structure that stores chunks of data in
its own storage, avoiding duplicates.
Created September 22, 2007 Vasil Dimov
*******************************************************/
/*******************************************************************//**
Copies data into the storage and returns a pointer to the copy. If the
same data chunk is already present, then pointer to it is returned.
Data chunks are considered to be equal if len1 == len2 and
memcmp(data1, data2, len1) == 0. If"data" is not present (and thus
data_len bytes need to be allocated) and the size of storage is going to
become more than "memlim" then "data" is not added and NULL is returned.
To disable this behavior "memlim" can be set to 0, which stands for "no limit". */ constvoid*
ha_storage_put_memlim( /*==================*/
ha_storage_t* storage, /*!< in/out: hash storage */ constvoid* data, /*!< in: data to store */
ulint data_len, /*!< in: data length */
ulint memlim) /*!< in: memory limit to obey */
{ const uint32_t fold= my_crc32c(0, data, data_len);
ha_storage_node_t** after = reinterpret_cast<ha_storage_node_t**>
(&storage->hash.cell_get(fold)->node); for (; *after; after= &(*after)->next) if ((*after)->data_len == data_len &&
!memcmp((*after)->data, data, data_len)) return (*after)->data;
/* not present */
/* check if we are allowed to allocate data_len bytes */ if (memlim > 0 && ha_storage_get_size(storage) + data_len > memlim) return nullptr;
/* we put the auxiliary node struct and the data itself in one
continuous block */
ha_storage_node_t *node= static_cast<ha_storage_node_t*>
(mem_heap_alloc(storage->heap, sizeof *node + data_len));
node->data_len= data_len;
node->data= &node[1];
node->next= nullptr;
memcpy(const_cast<void*>(node->data), data, data_len);
*after= node; return node->data;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.