/// <summary> /// Deserializes from the given stream, returns an optimized index. /// </summary> public static MappedAttributesIndex Deserialize(Stream stream, MappedAttributesIndexProfile profile) { var version = stream.ReadByte(); if (version > 1) { throw new Exception(string.Format("Cannot deserialize mapped attributes index: Invalid version #: {0}, upgrade Itinero.", version)); } var bytes = new byte[4]; stream.Read(bytes, 0, 4); var length = BitConverter.ToUInt32(bytes, 0); ArrayBase <uint> data; if (profile == null || profile.DataProfile == null) { data = Context.ArrayFactory.CreateMemoryBackedArray <uint>(length); data.CopyFrom(stream); } else { var position = stream.Position; var map = new MemoryMapStream(new CappedStream(stream, position, length * 4)); data = new Array <uint>(map.CreateUInt32(length), profile.DataProfile); stream.Seek(length * 4, SeekOrigin.Current); } var attributes = AttributesIndex.Deserialize(new LimitedStream(stream, stream.Position), true); return(new MappedAttributesIndex(data, attributes)); }
/// <summary> /// Used for deserialization. /// </summary> private MappedAttributesIndex(ArrayBase <uint> data, AttributesIndex attributes) { _data = data; _pointer = (int)_data.Length; _attributes = attributes; _reverseIndex = null; }
/// <summary> /// Creates a new mapped attributes index. /// </summary> public MappedAttributesIndex(AttributesIndexMode mode = AttributesIndexMode.ReverseCollectionIndex | AttributesIndexMode.ReverseStringIndex) { _data = new MemoryArray <uint>(1024); _attributes = new AttributesIndex(mode); _reverseIndex = new HugeDictionary <uint, int>(); for (var p = 0; p < _data.Length; p++) { _data[p] = _NO_DATA; } }
/// <summary> /// Adds a new tag collection. /// </summary> public static uint Add(this AttributesIndex index, params Attribute[] attributes) { return(index.Add(new AttributeCollection(attributes))); }
/// <summary> /// Adds a new attributes collection. /// </summary> public static uint Add(this AttributesIndex index, IEnumerable <Attribute> attributes) { return(index.Add(new AttributeCollection(attributes))); }