feat(util/name_map): add rename_map

This commit is contained in:
Leonardo de Moura 2014-12-31 17:56:55 -08:00
parent 1f13bfa4f7
commit e76ef18980
3 changed files with 26 additions and 1 deletions

View file

@ -4,6 +4,6 @@ add_library(util trace.cpp debug.cpp name.cpp name_set.cpp
realpath.cpp script_state.cpp script_exception.cpp rb_map.cpp realpath.cpp script_state.cpp script_exception.cpp rb_map.cpp
lua.cpp luaref.cpp lua_named_param.cpp stackinfo.cpp lean_path.cpp lua.cpp luaref.cpp lua_named_param.cpp stackinfo.cpp lean_path.cpp
serializer.cpp lbool.cpp thread_script_state.cpp bitap_fuzzy_search.cpp serializer.cpp lbool.cpp thread_script_state.cpp bitap_fuzzy_search.cpp
init_module.cpp thread.cpp memory_pool.cpp utf8.cpp) init_module.cpp thread.cpp memory_pool.cpp utf8.cpp name_map.cpp)
target_link_libraries(util ${LEAN_LIBS}) target_link_libraries(util ${LEAN_LIBS})

17
src/util/name_map.cpp Normal file
View file

@ -0,0 +1,17 @@
/*
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
*/
#include "util/name_map.h"
namespace lean {
name const & rename_map::find(name const & k) const {
name const * it = &k;
while (name const * new_it = name_map<name>::find(*it)) {
it = new_it;
}
return *it;
}
}

View file

@ -9,4 +9,12 @@ Author: Leonardo de Moura
#include "util/name.h" #include "util/name.h"
namespace lean { namespace lean {
template<typename T> using name_map = rb_map<name, T, name_quick_cmp>; template<typename T> using name_map = rb_map<name, T, name_quick_cmp>;
class rename_map : public name_map<name> {
public:
// Similar to name_map::find, but it "follows" the sequence of renames.
// Example, if map contains "A->B" and "B->C", then find(A) returns C.
// Moreover, if k is not in the map, the result is \c k
name const & find(name const & k) const;
};
} }