Added indexed array data type with variable and fixed group blocks
This commit is contained in:
committed by
Patrick Niklaus
parent
cedeb15ade
commit
6e1c4bfecd
+31
-34
@@ -1,64 +1,58 @@
|
||||
#include "util/name_table.hpp"
|
||||
#include "storage/io.hpp"
|
||||
#include "util/exception.hpp"
|
||||
#include "util/log.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace util
|
||||
{
|
||||
|
||||
NameTable::NameTable(const std::string &filename)
|
||||
NameTable::NameTable(const std::string &file_name)
|
||||
{
|
||||
storage::io::FileReader name_stream_file_reader(filename,
|
||||
storage::io::FileReader::HasNoFingerprint);
|
||||
using FileReader = storage::io::FileReader;
|
||||
|
||||
m_name_table.ReadARangeTable(name_stream_file_reader);
|
||||
FileReader name_stream_file_reader(file_name, FileReader::HasNoFingerprint);
|
||||
const auto file_size = name_stream_file_reader.GetSize();
|
||||
|
||||
const auto number_of_chars = name_stream_file_reader.ReadElementCount32();
|
||||
m_buffer = BufferType(static_cast<ValueType *>(::operator new(file_size)),
|
||||
[](void *ptr) { ::operator delete(ptr); });
|
||||
name_stream_file_reader.ReadInto<char>(m_buffer.get(), file_size);
|
||||
m_name_table.reset(m_buffer.get(), m_buffer.get() + file_size);
|
||||
|
||||
m_names_char_list.resize(number_of_chars + 1); //+1 gives sentinel element
|
||||
m_names_char_list.back() = 0;
|
||||
if (number_of_chars > 0)
|
||||
{
|
||||
name_stream_file_reader.ReadInto(&m_names_char_list[0], number_of_chars);
|
||||
}
|
||||
else
|
||||
if (m_name_table.empty())
|
||||
{
|
||||
util::Log() << "list of street names is empty in construction of name table from: \""
|
||||
<< filename << "\"";
|
||||
<< file_name << "\"";
|
||||
}
|
||||
}
|
||||
|
||||
void NameTable::reset(ValueType *begin, ValueType *end)
|
||||
{
|
||||
m_buffer.reset();
|
||||
m_name_table.reset(begin, end);
|
||||
}
|
||||
|
||||
StringView NameTable::GetNameForID(const NameID id) const
|
||||
{
|
||||
if (std::numeric_limits<NameID>::max() == id)
|
||||
{
|
||||
if (id == INVALID_NAMEID)
|
||||
return {};
|
||||
}
|
||||
|
||||
auto range = m_name_table.GetRange(id);
|
||||
return m_name_table.at(id);
|
||||
}
|
||||
|
||||
if (range.begin() == range.end())
|
||||
{
|
||||
StringView NameTable::GetDestinationsForID(const NameID id) const
|
||||
{
|
||||
if (id == INVALID_NAMEID)
|
||||
return {};
|
||||
}
|
||||
|
||||
auto first = begin(m_names_char_list) + range.front();
|
||||
auto last = begin(m_names_char_list) + range.back() + 1;
|
||||
const std::size_t len = last - first;
|
||||
|
||||
return StringView{&*first, len};
|
||||
return m_name_table.at(id + 1);
|
||||
}
|
||||
|
||||
StringView NameTable::GetRefForID(const NameID id) const
|
||||
{
|
||||
if (id == INVALID_NAMEID)
|
||||
return {};
|
||||
|
||||
// Way string data is stored in blocks based on `id` as follows:
|
||||
//
|
||||
// | name | destination | pronunciation | ref |
|
||||
@@ -71,11 +65,14 @@ StringView NameTable::GetRefForID(const NameID id) const
|
||||
// Offset 0 is name, 1 is destination, 2 is pronunciation, 3 is ref.
|
||||
// See datafacades and extractor callbacks for details.
|
||||
const constexpr auto OFFSET_REF = 3u;
|
||||
return GetNameForID(id + OFFSET_REF);
|
||||
return m_name_table.at(id + OFFSET_REF);
|
||||
}
|
||||
|
||||
StringView NameTable::GetPronunciationForID(const NameID id) const
|
||||
{
|
||||
if (id == INVALID_NAMEID)
|
||||
return {};
|
||||
|
||||
// Way string data is stored in blocks based on `id` as follows:
|
||||
//
|
||||
// | name | destination | pronunciation | ref |
|
||||
@@ -88,7 +85,7 @@ StringView NameTable::GetPronunciationForID(const NameID id) const
|
||||
// Offset 0 is name, 1 is destination, 2 is pronunciation, 3 is ref.
|
||||
// See datafacades and extractor callbacks for details.
|
||||
const constexpr auto OFFSET_PRONUNCIATION = 2u;
|
||||
return GetNameForID(id + OFFSET_PRONUNCIATION);
|
||||
return m_name_table.at(id + OFFSET_PRONUNCIATION);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
|
||||
Reference in New Issue
Block a user