GeoDesk for C++
Fast and storage-efficient spatial database engine for OpenStreetMap features
Loading...
Searching...
No Matches
geodesk::Key Class Reference

A lightweight wrapper for a key string. More...

#include <Key.h>

Public Member Functions

const char * data () const noexcept
 The character data of the key string.
 
uint32_t size () const noexcept
 The size of the key string (in bytes, not characters).
 
int code () const noexcept
 The global-string code of this Key, or -1 if it is not in the global-string table.
 
bool operator== (const Key &) const =default
 
bool operator!= (const Key &) const =default
 

Detailed Description

A lightweight wrapper for a key string.

A Key is constructed from a std::string_view via Features::key() and is valid for all features within the same GOL. A Key created for one GOL cannot be used for lookups in another.

A Key object is useful in scenarios requiring lookups of the same tag across multiple features. It avoids the overhead of resolving the tag's global-string code on every lookup, leading to a performance boost of about 2x to 4x.

Key houseNumber = buildings.key("addr:housenumber");
for(Feature building: buildings)
{
TagValue hn = building[houseNumber];
// This is faster than:
TagValue hnSlow = building["addr:housenumber"];
}
A geographic feature.
Definition Feature.h:27
A lightweight wrapper for a key string.
Definition Key.h:42
The value of a Tag.
Definition TagValue.h:33

Key converts implicitly to std::string_view.

Warning
The memory backing the std::string_view used to create this Key must remain unchanged and valid for the Key's entire lifetime to avoid undefined behavior.
See also
Tags, Feature

Member Function Documentation

◆ code()

int geodesk::Key::code ( ) const
inlinenoexcept

The global-string code of this Key, or -1 if it is not in the global-string table.

◆ data()

const char * geodesk::Key::data ( ) const
inlinenoexcept

The character data of the key string.

Note: The string is not guaranteed to 0-trminated.

◆ operator!=()

bool geodesk::Key::operator!= ( const Key & ) const
default

◆ operator==()

bool geodesk::Key::operator== ( const Key & ) const
default

◆ size()

uint32_t geodesk::Key::size ( ) const
inlinenoexcept

The size of the key string (in bytes, not characters).


The documentation for this class was generated from the following file: