Skip to content

Commit 4ff0c2e

Browse files
committed
feat: implement erase methods in webcc::map for iterator and key-based removal
1 parent c3f090e commit 4ff0c2e

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

include/webcc/core/map.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,30 @@ namespace webcc
122122
const_iterator begin() const { return const_iterator{data_.data()}; }
123123
const_iterator end() const { return const_iterator{data_.data() + data_.size()}; }
124124

125+
iterator erase(iterator pos)
126+
{
127+
if (pos == end())
128+
{
129+
return pos;
130+
}
131+
132+
size_t index = static_cast<size_t>(pos.ptr - data_.data());
133+
data_.erase(index);
134+
return iterator{data_.data() + index};
135+
}
136+
137+
size_t erase(const Key &key)
138+
{
139+
int idx = index_of(key);
140+
if (idx < 0)
141+
{
142+
return 0;
143+
}
144+
145+
data_.erase(static_cast<size_t>(idx));
146+
return 1;
147+
}
148+
125149
bool empty() const { return data_.empty(); }
126150
size_t size() const { return data_.size(); }
127151
void clear() { data_.clear(); }

0 commit comments

Comments
 (0)