public static bool CompareOpposite(AttributesIndex tags, uint tags1, uint tags2) { TagsCollectionBase tags3 = tags.Get(tags1); TagsCollectionBase tags4 = tags.Get(tags2); bool?nullable1 = Vehicle.Car.IsOneWay(tags3); bool?nullable2 = Vehicle.Car.IsOneWay(tags4); if (nullable1.HasValue && nullable2.HasValue && nullable1.Value == nullable2.Value) { return(false); } foreach (Tag tag in tags3) { if (tag.Key != "oneway" && !tags4.ContainsKeyValue(tag.Key, tag.Value)) { return(false); } } foreach (Tag tag in tags4) { if (tag.Key != "oneway" && !tags3.ContainsKeyValue(tag.Key, tag.Value)) { return(false); } } return(true); }
/// <summary> /// Compares two highway tag collections and check if they mean the same. /// </summary> /// <returns></returns> public static bool Compare(AttributesIndex tags, uint tags1, uint tags2) { var tagsCollection1 = tags.Get(tags1); var tagsCollection2 = tags.Get(tags2); var oneway1 = Vehicle.Car.IsOneWay(tagsCollection1); var oneway2 = Vehicle.Car.IsOneWay(tagsCollection2); if (oneway1 != null && oneway2 != null && oneway1.Value != oneway2.Value) { // both have values but opposite ones. return(false); } foreach (var tag1 in tagsCollection1) { if (tag1.Key != "oneway") { if (!tagsCollection2.Contains(tag1.Key, tag1.Value)) { return(false); } } } foreach (var tag2 in tagsCollection2) { if (tag2.Key != "oneway") { if (!tagsCollection1.Contains(tag2.Key, tag2.Value)) { return(false); } } } return(true); }
/// <summary> /// Gets a stop if there is one for the given vertex and the associated meta-data. Returns null if no stop is found. /// </summary> public IAttributeCollection GetStop(uint vertex) { for (uint p = 0; p < _stops.Length; p += 2) { if (_stops[p + 0] == vertex) { return(_stopsMeta.Get(_stops[p + 1])); } } return(null); }
/// <summary> /// Gets a shortcut. /// </summary> public uint[] Get(uint id, out IAttributeCollection meta) { var size = _shortcuts[id]; meta = _shortcutsMeta.Get(_shortcuts[id + 1]); var vertices = new uint[size - 2]; for (var pointer = id + 2; pointer < id + size; pointer++) { vertices[pointer - id - 2] = _shortcuts[pointer]; } return(vertices); }
/// <summary> /// Moves the enumerator until the trip that satisfies the filter. /// </summary> public static bool MoveUntil(this TripsDb.Enumerator enumerator, AttributesIndex tripAttributes, Func <IAttributeCollection, bool> filter) { if (enumerator == null) { throw new ArgumentNullException(nameof(enumerator)); } if (filter == null) { throw new ArgumentNullException(nameof(filter)); } while (enumerator.MoveNext()) { var meta = tripAttributes.Get(enumerator.MetaId); if (filter(meta)) { return(true); } } return(false); }
public void TestGet() { var index = new AttributesIndex(); var id1 = index.Add(new Attribute("key1", "value1")); var id2 = index.Add(new Attribute("key2", "value1")); var id3 = index.Add(new Attribute("key2", "value2")); var attributes = index.Get(id1); Assert.IsNotNull(attributes); Assert.AreEqual(1, attributes.Count); Assert.AreEqual("key1", attributes.First().Key); Assert.AreEqual("value1", attributes.First().Value); attributes = index.Get(id2); Assert.IsNotNull(attributes); Assert.AreEqual(1, attributes.Count); Assert.AreEqual("key2", attributes.First().Key); Assert.AreEqual("value1", attributes.First().Value); attributes = index.Get(id3); Assert.IsNotNull(attributes); Assert.AreEqual(1, attributes.Count); Assert.AreEqual("key2", attributes.First().Key); Assert.AreEqual("value2", attributes.First().Value); var random = new System.Random(116542346); var keys = 100; var values = 100000; index = new AttributesIndex(); var refIndex = new Dictionary <uint, IAttributeCollection>(); for (var i = 0; i < 1000; i++) { attributes = new AttributeCollection(); for (var j = 0; j < random.Next(8); j++) { attributes.AddOrReplace(new Attribute( string.Format("k{0}", random.Next(keys)), string.Format("v{0}", random.Next(values)))); } var id = index.Add(attributes); refIndex[id] = attributes; } foreach (var refAttribute in refIndex) { attributes = index.Get(refAttribute.Key); Assert.AreEqual(refAttribute.Value.Count, attributes.Count); foreach (var attribute in refAttribute.Value) { Assert.IsTrue(attributes.Contains(attribute.Key, attribute.Value)); } foreach (var attribute in attributes) { Assert.IsTrue(refAttribute.Value.Contains(attribute.Key, attribute.Value)); } } index = new AttributesIndex(AttributesIndexMode.IncreaseOne); id1 = index.Add(new Attribute("key1", "value1")); id2 = index.Add(new Attribute("key2", "value1")); id3 = index.Add(new Attribute("key2", "value2")); attributes = index.Get(id1); Assert.IsNotNull(attributes); Assert.AreEqual(1, attributes.Count); Assert.AreEqual("key1", attributes.First().Key); Assert.AreEqual("value1", attributes.First().Value); attributes = index.Get(id2); Assert.IsNotNull(attributes); Assert.AreEqual(1, attributes.Count); Assert.AreEqual("key2", attributes.First().Key); Assert.AreEqual("value1", attributes.First().Value); attributes = index.Get(id3); Assert.IsNotNull(attributes); Assert.AreEqual(1, attributes.Count); Assert.AreEqual("key2", attributes.First().Key); Assert.AreEqual("value2", attributes.First().Value); random = new System.Random(116542346); keys = 100; values = 100000; index = new AttributesIndex(AttributesIndexMode.IncreaseOne); refIndex = new Dictionary <uint, IAttributeCollection>(); for (var i = 0; i < 1000; i++) { attributes = new AttributeCollection(); for (var j = 0; j < random.Next(8); j++) { attributes.AddOrReplace(new Attribute( string.Format("k{0}", random.Next(keys)), string.Format("v{0}", random.Next(values)))); } var id = index.Add(attributes); refIndex[id] = attributes; } foreach (var refAttribute in refIndex) { attributes = index.Get(refAttribute.Key); Assert.AreEqual(refAttribute.Value.Count, attributes.Count); foreach (var attribute in refAttribute.Value) { Assert.IsTrue(attributes.Contains(attribute.Key, attribute.Value)); } foreach (var attribute in attributes) { Assert.IsTrue(refAttribute.Value.Contains(attribute.Key, attribute.Value)); } } }