Open droogmic opened 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
https://wiki.openstreetmap.org/wiki/Tags
Requirements
Key
A key type, at its simplest it could be a
&'static str
orString
. See also: https://lib.rs/crates/kstring.&'static str
s.Add
trait implemented to support:
joined keys (i.e.A + B + C == "a:b:c"
)Value
A value type, at its simplest it could be a
&'static str
orString
. 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
orBTreeMap
<K, V>
, for example:fn get<Q>(&self, key: &Q) -> Option<V>
fn is<Q, U>(&self, key: &Q, value: &U) -> bool
fn is_any<Q, W>(&self, key: &Q, values: &W) -> bool
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:Performance Constraints
In addition to the constraints on the key (see kstring):
foo:bar
usingfoo
will be O(N).:
split cost when not needed, i.e.get("foo" + "bar")
must not allocate aString("foo:bar")
which is then.split_once(':')
.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.