Select one of the symbols to view example projects that use it.
 
Outline
#include "nvs_item_hash_list.hpp"
nvs
Files
loading...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/nvs_flash/src/nvs_item_hash_list.cpp
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include "nvs_item_hash_list.hpp" namespace nvs { HashList::HashList() { }{ ... } void HashList::clear() { for (auto it = mBlockList.begin(); it != mBlockList.end();) { auto tmp = it; ++it; mBlockList.erase(tmp); delete static_cast<HashListBlock*>(tmp); }{...} }{ ... } HashList::~HashList() { clear(); }{ ... } HashList::HashListBlock::HashListBlock() { static_assert(sizeof(HashListBlock) == HashListBlock::BYTE_SIZE, "cache block size calculation incorrect"); }{ ... } esp_err_t HashList::insert(const Item& item, size_t index) { const uint32_t hash_24 = item.calculateCrc32WithoutValue() & 0xffffff; // add entry to the end of last block if possible if (mBlockList.size()) { auto& block = mBlockList.back(); if (block.mCount < HashListBlock::ENTRY_COUNT) { block.mNodes[block.mCount++] = HashListNode(hash_24, index); return ESP_OK; }{...} }{...} // if the above failed, create a new block and add entry to it HashListBlock* newBlock = new (std::nothrow) HashListBlock; if (!newBlock) return ESP_ERR_NO_MEM; mBlockList.push_back(newBlock); newBlock->mNodes[0] = HashListNode(hash_24, index); newBlock->mCount++; return ESP_OK; }{ ... } bool HashList::erase(size_t index) { for (auto it = mBlockList.begin(); it != mBlockList.end();) { bool haveEntries = false; bool foundIndex = false; for (size_t i = 0; i < it->mCount; ++i) { if (it->mNodes[i].mIndex == index) { it->mNodes[i].mIndex = 0xff; foundIndex = true; /* found the item and removed it */ }{...} if (it->mNodes[i].mIndex != 0xff) { haveEntries = true; }{...} if (haveEntries && foundIndex) { /* item was found, and HashListBlock still has some items */ return true; }{...} }{...} /* no items left in HashListBlock, can remove */ if (!haveEntries) { auto tmp = it; ++it; mBlockList.erase(tmp); delete static_cast<HashListBlock*>(tmp); }{...} else { ++it; }{...} if (foundIndex) { /* item was found and empty HashListBlock was removed */ return true; }{...} }{...} // item hasn't been present in cache"); return false; }{ ... } size_t HashList::find(size_t start, const Item& item) { const uint32_t hash_24 = item.calculateCrc32WithoutValue() & 0xffffff; for (auto it = mBlockList.begin(); it != mBlockList.end(); ++it) { for (size_t index = 0; index < it->mCount; ++index) { HashListNode& e = it->mNodes[index]; if (e.mIndex >= start && e.mHash == hash_24 && e.mIndex != 0xff) { return e.mIndex; }{...} }{...} }{...} return SIZE_MAX; }{ ... } }{...} // namespace nvs
Details