-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pw_containers: Add IntrusiveMap and IntrusiveMultiMap
This CL adds intrusive, ordered maps backed by an AA tree implementation. These can be used for associative dictionaries or for sorted lists, among other uses. Change-Id: I81194bcdbff70a807f52547e99a04649c5b61635 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/216828 Lint: Lint 🤖 <[email protected]> Reviewed-by: Wyatt Hepler <[email protected]> Commit-Queue: Aaron Green <[email protected]>
- Loading branch information
1 parent
e8ab2b0
commit 8a3250d
Showing
15 changed files
with
3,664 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2024 The Pigweed Authors | ||
// | ||
// 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 | ||
// | ||
// https://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 "pw_containers/internal/aa_tree.h" | ||
|
||
namespace pw::containers::internal { | ||
|
||
void GenericAATree::SetRoot(AATreeItem* item) { | ||
if (item != nullptr) { | ||
item->parent_.set(nullptr); | ||
} | ||
root_ = item; | ||
} | ||
|
||
size_t GenericAATree::size() const { | ||
return empty() ? 0 : root_->GetTreeSize(); | ||
} | ||
|
||
void GenericAATree::clear() { | ||
if (root_ != nullptr) { | ||
root_->Clear(); | ||
SetRoot(nullptr); | ||
} | ||
} | ||
|
||
GenericAATree::iterator GenericAATree::erase(AATreeItem& item) { | ||
if (item.GetRoot() != root_) { | ||
return iterator(&root_); | ||
} | ||
AATreeItem* next = item.GetSuccessor(); | ||
SetRoot(item.Unmap()); | ||
return iterator(&root_, next); | ||
} | ||
|
||
GenericAATree::iterator GenericAATree::erase(AATreeItem& first, | ||
AATreeItem& last) { | ||
iterator iter(&root_, &first); | ||
while (&(*iter) != &last) { | ||
iter = erase(*iter); | ||
} | ||
return iter; | ||
} | ||
|
||
void GenericAATree::swap(GenericAATree& other) { | ||
std::swap(root_, other.root_); | ||
} | ||
|
||
} // namespace pw::containers::internal |
Oops, something went wrong.