a-b-street / osm2lanes

A common library and set of test cases for transforming OSM tags to lane specifications
https://a-b-street.github.io/osm2lanes/
Apache License 2.0
34 stars 2 forks source link

Tags Data Structure #78

Open droogmic opened 2 years ago

droogmic commented 2 years ago

https://wiki.openstreetmap.org/wiki/Tags

Requirements

Key

A key type, at its simplest it could be a &'static str or String. See also: https://lib.rs/crates/kstring.

Value

A value type, at its simplest it could be a &'static str or String. Trait implemented to support ; joined keys. The result should also resemble an iterable. Example: [A, B, C].into() == "a;b;c".

Mapping

Support interaction mimicking a HashMap or BTreeMap <K, V>, for example:

Arguments of type Q should be possible directly from a &'static str, .e.g. tags.get("highway").

Tree

Support access as a tree structure, for : separated keys. Example:

// foo:bar:baz=toto
tags.tree().get("foo").unwrap().get("bar").unwrap().is("baz", "toto")

Performance Constraints

In addition to the constraints on the key (see kstring):

Deployment

For now, this should replace https://github.com/a-b-street/osm2lanes/tree/main/rust/osm2lanes/src/tag. Once proven, a separate crate should be made.

droogmic commented 2 years ago

for key types: https://github.com/epage/string-benchmarks-rs

Suggestions:

  • Generally, String
  • If you deal mostly with string literals but want some flexibility (like clap), generally you'll want Cow<'static, str>
  • If a profiler says your strings are a problem: Try different crates and settings for that crate out with a profiler O(1) clones are important when doing a lot of clones. For one-off allocations, they are slower. For short-lived programs, look into string interning