34 std::vector<NamePrefixList::NamePair> namePairs;
35 std::transform(names.begin(), names.end(), std::back_inserter(namePairs),
36 [] (
const ndn::Name& name) {
39 m_names = std::move(namePairs);
43 : m_names(namesAndSources)
51 std::vector<NamePrefixList::NamePair>::iterator
52 NamePrefixList::get(
const ndn::Name& name)
54 return std::find_if(m_names.begin(), m_names.end(),
56 return name == std::get<NamePrefixList::NamePairIndex::NAME>(pair);
60 std::vector<std::string>::iterator
61 NamePrefixList::getSource(
const std::string& source, std::vector<NamePair>::iterator& entry)
63 return std::find_if(std::get<NamePairIndex::SOURCES>(*entry).begin(),
64 std::get<NamePairIndex::SOURCES>(*entry).end(),
65 [&] (
const std::string& containerSource) {
66 return source == containerSource;
73 auto pairItr =
get(name);
74 if (pairItr == m_names.end()) {
75 std::vector<std::string> sources{source};
76 m_names.push_back(std::tie(name, sources));
80 std::vector<std::string>& sources = std::get<NamePrefixList::NamePairIndex::SOURCES>(*pairItr);
81 auto sourceItr = getSource(source, pairItr);
82 if (sourceItr == sources.end()) {
83 sources.push_back(source);
93 auto pairItr =
get(name);
94 if (pairItr != m_names.end()) {
95 std::vector<std::string>& sources = std::get<NamePrefixList::NamePairIndex::SOURCES>(*pairItr);
96 auto sourceItr = getSource(source, pairItr);
97 if (sourceItr != sources.end()) {
98 sources.erase(sourceItr);
99 if (sources.size() == 0) {
100 m_names.erase(pairItr);
111 return m_names == other.m_names;
117 std::sort(m_names.begin(), m_names.end());
123 std::list<ndn::Name> names;
124 for (
const auto& namePair : m_names) {
125 names.push_back(std::get<NamePrefixList::NamePairIndex::NAME>(namePair));
136 const std::vector<std::string>
139 auto it = std::find_if(m_names.begin(), m_names.end(),
141 return name == std::get<NamePrefixList::NamePairIndex::NAME>(pair);
143 if (it != m_names.end()) {
144 return std::get<NamePrefixList::NamePairIndex::SOURCES>(*it);
147 return std::vector<std::string>{};
153 os <<
"Name prefix list: {\n";
154 for (
const auto& name : list.
getNames()) {
157 for (
const auto& source : list.
getSources(name)) {
158 os <<
" " << source <<
"\n";
161 os <<
"}" << std::endl;
bool remove(const ndn::Name &name, const std::string &source="")
removes name from NamePrefixList
std::ostream & operator<<(std::ostream &os, const Adjacent &adjacent)
std::list< ndn::Name > getNames() const
bool operator==(const NamePrefixList &other) const
std::tuple< ndn::Name, std::vector< std::string >> NamePair
bool insert(const ndn::Name &name, const std::string &source="")
inserts name into NamePrefixList
const std::vector< std::string > getSources(const ndn::Name &name) const
Copyright (c) 2014-2017, The University of Memphis, Regents of the University of California.
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
uint32_t countSources(const ndn::Name &name) const