diff options
author | David Robillard <d@drobilla.net> | 2017-03-26 19:10:45 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2017-03-26 19:10:45 +0200 |
commit | 3c3feab0d385a927e77e75485a6f9c0320c954d3 (patch) | |
tree | c100549a434755400cfaeb753d492a697dc9a042 /src/Store.cpp | |
parent | d5eb49e1e468377fea4c5f13840d0435714d34c4 (diff) | |
download | ingen-3c3feab0d385a927e77e75485a6f9c0320c954d3.tar.gz ingen-3c3feab0d385a927e77e75485a6f9c0320c954d3.tar.bz2 ingen-3c3feab0d385a927e77e75485a6f9c0320c954d3.zip |
Make Store keyed by URI instead of Path
Diffstat (limited to 'src/Store.cpp')
-rw-r--r-- | src/Store.cpp | 51 |
1 files changed, 14 insertions, 37 deletions
diff --git a/src/Store.cpp b/src/Store.cpp index e2f0f368..ba41bffc 100644 --- a/src/Store.cpp +++ b/src/Store.cpp @@ -25,24 +25,15 @@ namespace Ingen { void Store::add(Node* o) { - if (find(o->path()) != end()) { + if (find(o->uri()) != end()) { return; } - insert(make_pair(o->path(), SPtr<Node>(o))); + insert(make_pair(o->uri(), SPtr<Node>(o))); } -/* - TODO: These methods are currently O(n_children) but should logarithmic. The - std::map methods do not allow passing a comparator, but std::upper_bound - does. This should be achievable by making a rooted comparator that is a - normal ordering except compares a special sentinel value as the greatest - element that is a child of the parent. Searching for this sentinel should - then find the end of the descendants in logarithmic time. -*/ - Store::iterator -Store::find_descendants_end(const iterator parent) +Store::find_descendants_end(iterator parent) { iterator descendants_end = parent; ++descendants_end; @@ -55,28 +46,13 @@ Store::find_descendants_end(const iterator parent) } Store::const_iterator -Store::find_descendants_end(const const_iterator parent) const -{ - const_iterator descendants_end = parent; - ++descendants_end; - while (descendants_end != end() && - descendants_end->first.is_child_of(parent->first)) { - ++descendants_end; - } - - return descendants_end; -} - -Store::const_range -Store::children_range(SPtr<const Node> o) const +Store::find_first_child(SPtr<const Node> o) const { - const const_iterator parent = find(o->path()); - if (parent != end()) { - const_iterator first_child = parent; - ++first_child; - return std::make_pair(first_child, find_descendants_end(parent)); + const_iterator i = find(o->uri()); + if (i == end()) { + return i; } - return make_pair(end(), end()); + return ++i; } void @@ -92,7 +68,7 @@ Store::remove(const iterator top, Objects& removed) void Store::rename(const iterator top, const Raul::Path& new_path) { - const Raul::Path old_path = top->first; + const Raul::Path old_path = uri_to_path(top->first); // Remove the object and all its descendants Objects removed; @@ -100,14 +76,15 @@ Store::rename(const iterator top, const Raul::Path& new_path) // Rename all the removed objects for (Objects::const_iterator i = removed.begin(); i != removed.end(); ++i) { - const Raul::Path path = (i->first == old_path) + const Raul::Path old = uri_to_path(i->first); + const Raul::Path path = (old == old_path) ? new_path : new_path.child( - Raul::Path(i->first.substr(old_path.base().length() - 1))); + Raul::Path(old.substr(old_path.base().length() - 1))); i->second->set_uri(path_to_uri(path)); assert(find(path) == end()); // Shouldn't be dropping objects! - insert(make_pair(path, i->second)); + insert(make_pair(path_to_uri(path), i->second)); } } @@ -124,7 +101,7 @@ Store::child_name_offset(const Raul::Path& parent, if (offset > 0) { ss << "_" << offset; } - if (find(parent.child(Raul::Symbol(ss.str()))) == end() && + if (find(path_to_uri(parent.child(Raul::Symbol(ss.str())))) == end() && (allow_zero || offset > 0)) { break; } else if (offset == 0) { |