public override void Build() { var sw = new Stopwatch(); sw.Start(); var kvUsageMemoryStream = new MemoryStream(); KvUsage = new KeyValueUsage(kvUsageMemoryStream); var keyValueStoreFile = new MemoryStream(); KvIndex = new KeyValueIndex(Settings.Search.KvIndexCapacity, Settings.Search.PrefixLength); KvStore = new KeyValueStore(KvIndex, KvUsage, keyValueStoreFile); var storeFile = new MemoryStream(); Store = new ElementStore(KvStore, storeFile, ObjectPool); Tree = new RTree <uint>(65); _reader.Read(new ReaderContext { SourceStream = _sourceStream, Builder = this, ReuseEntities = false, SkipTags = false, }); Clear(); Complete(); sw.Stop(); Trace.Debug(CategoryKey, Strings.IndexBuildInMs, sw.ElapsedMilliseconds.ToString()); }
/// <summary> /// Creates instance of <see cref="ElementSource" /> from streams and /// created spatial index. /// </summary> internal ElementSource(BoundingBox boundingBox, KeyValueUsage keyValueUsage, KeyValueIndex keyValueIndex, KeyValueStore keyValueStore, ElementStore elementStore, ISpatialIndex <uint> spatialIndex) { BoundingBox = boundingBox; KvUsage = keyValueUsage; KvIndex = keyValueIndex; KvStore = keyValueStore; ElementStore = elementStore; SpatialIndexTree = spatialIndex; IsReadOnly = true; }
/// <summary> Creates instance of <see cref="ElementSource" /> from persistent storage. </summary> /// <param name="directory">Already resolved directory which contains all indecies.</param> /// <param name="fileService">File system service.</param> /// <param name="objectPool">ObjectPool.</param> internal ElementSource(string directory, IFileSystemService fileService, IObjectPool objectPool) { // load map data from streams BoundingBox = PersistentIndexBuilder.ReadBoundingBox(fileService.ReadStream(string.Format(MapConsts.HeaderPathFormat, directory))); KvUsage = new KeyValueUsage(fileService.ReadStream(string.Format(MapConsts.KeyValueUsagePathFormat, directory))); KvIndex = KeyValueIndex.Load(fileService.ReadStream(string.Format(MapConsts.KeyValueIndexPathFormat, directory))); KvStore = new KeyValueStore(KvIndex, KvUsage, fileService.ReadStream(string.Format(MapConsts.KeyValueStorePathFormat, directory))); ElementStore = new ElementStore(KvStore, fileService.ReadStream(string.Format(MapConsts.ElementStorePathFormat, directory)), objectPool); SpatialIndexTree = SpatialIndex.Load(fileService.ReadStream(string.Format(MapConsts.SpatialIndexPathFormat, directory))); IsReadOnly = true; }
public void Setup() { var buffer = new byte[256]; var stream = new MemoryStream(buffer); stream.WriteByte(4); stream.WriteByte(7); var kvUsage = new KeyValueUsage(new MemoryStream(1000)); var index = new KeyValueIndex(100, 3); _store = new KeyValueStore(index, kvUsage, stream); }
public void CanCreateAddGetOne() { // ARRANGE var index = new KeyValueIndex(Capacity, PrefixLength); var pair = new KeyValuePair <string, string>("addr", "eic"); uint offset = 2; // ACT index.Add(pair, offset); var result = index.GetOffset(pair); // ASSERT Assert.AreEqual(offset, result); }
public void Setup() { var keyValueStream = new MemoryStream(new byte[256]); keyValueStream.WriteByte(4); keyValueStream.WriteByte(7); var kvUsage = new KeyValueUsage(new MemoryStream(1000)); var index = new KeyValueIndex(100, 3); var keyValueStore = new KeyValueStore(index, kvUsage, keyValueStream); var elementStoreStream = new MemoryStream(new byte[10000]); _store = new ElementStore(keyValueStore, elementStoreStream, TestHelper.GetObjectPool()); }
public override void Build() { var sw = new Stopwatch(); sw.Start(); var sourceStream = _fileSystemService.ReadStream(_filePath); var format = _filePath.Split('.').Last(); var reader = GetReader(format); var kvUsageMemoryStream = new MemoryStream(); var kvUsage = new KeyValueUsage(kvUsageMemoryStream); var keyValueStoreFile = _fileSystemService.WriteStream(String.Format(MapConsts.KeyValueStorePathFormat, _outputDirectory)); var index = new KeyValueIndex(Settings.Search.KvIndexCapacity, Settings.Search.PrefixLength); var keyValueStore = new KeyValueStore(index, kvUsage, keyValueStoreFile); var storeFile = _fileSystemService.WriteStream(String.Format(MapConsts.ElementStorePathFormat, _outputDirectory)); Store = new ElementStore(keyValueStore, storeFile, ObjectPool); Tree = new RTree <uint>(65); reader.Read(new ReaderContext { SourceStream = sourceStream, Builder = this, ReuseEntities = false, SkipTags = false, }); Clear(); Complete(); using (var kvFileStream = _fileSystemService.WriteStream(String.Format(MapConsts.KeyValueUsagePathFormat, _outputDirectory))) { var buffer = kvUsageMemoryStream.GetBuffer(); kvFileStream.Write(buffer, 0, (int)kvUsageMemoryStream.Length); } KeyValueIndex.Save(index, _fileSystemService.WriteStream(String.Format(MapConsts.KeyValueIndexPathFormat, _outputDirectory))); SpatialIndex.Save(Tree, _fileSystemService.WriteStream(String.Format(MapConsts.SpatialIndexPathFormat, _outputDirectory))); Store.Dispose(); sw.Stop(); Trace.Debug(CategoryKey, Strings.IndexBuildInMs, sw.ElapsedMilliseconds.ToString()); }
public void Setup() { var boundingBox = new BoundingBox(new GeoCoordinate(52.0, 13.0), new GeoCoordinate(52.2, 13.2)); var keyValueStream = new MemoryStream(new byte[256]); keyValueStream.WriteByte(4); keyValueStream.WriteByte(7); var kvIndex = new KeyValueIndex(100, 3); var kvUsage = new KeyValueUsage(new MemoryStream(1000)); var kvStore = new KeyValueStore(kvIndex, kvUsage, keyValueStream); var elementStoreStream = new MemoryStream(new byte[10000]); var elementStore = new ElementStore(kvStore, elementStoreStream, TestHelper.GetObjectPool()); var tree = new RTree <uint>(); var node = new Node() { Id = 1, Coordinate = new GeoCoordinate(52.0, 13.0), Tags = new Dictionary <string, string>() { { "key1", "value1" }, { "key2", "value2" } }.ToTags() }; var nodeOffset = elementStore.Insert(node); tree.Insert(nodeOffset, new PointEnvelop(node.Coordinate)); var way = new Way() { Id = 2, Coordinates = new List <GeoCoordinate>() { new GeoCoordinate(52.1, 13.1), new GeoCoordinate(52.2, 13.2) }, Tags = new Dictionary <string, string>() { { "key1", "value1" }, { "key2", "value2" } }.ToTags() }; var wayOffset = elementStore.Insert(way); tree.Insert(wayOffset, new Envelop(way.Coordinates.First(), way.Coordinates.Last())); _source = new ElementSource(boundingBox, kvUsage, kvIndex, kvStore, elementStore, tree); }
public void CanCreateAddGetMultiply() { // ARRANGE var index = new KeyValueIndex(Capacity, PrefixLength); // ACT & ASSERT for (int i = 0; i < 3; i++) { index.Add(new KeyValuePair <string, string>(i.ToString(), (i + 1).ToString()), (uint)i * 10); } for (int i = 0; i < 3; i++) { var offset = index.GetOffset(new KeyValuePair <string, string>(i.ToString(), (i + 1).ToString())); Assert.AreEqual((uint)i * 10, offset); } }
public void CanSaveAndLoad() { // ARRANGE var index = new KeyValueIndex(Capacity, PrefixLength); var buffer = new byte[Capacity * 4 + 4 + 4]; var stream = new MemoryStream(buffer); // fill with some test data for (int i = 0; i < 3; i++) { index.Add(new KeyValuePair <string, string>(i.ToString(), (i + 1).ToString()), (uint)i * 10); } // ACT KeyValueIndex.Save(index, stream); var result = KeyValueIndex.Load(new MemoryStream(buffer)); // ARRANGE for (int i = 0; i < 3; i++) { var offset = result.GetOffset(new KeyValuePair <string, string>(i.ToString(), (i + 1).ToString())); Assert.AreEqual((uint)i * 10, offset); } }
private bool Equals(KeyValueIndex <TKey> other) => other._fromOriginalValues == _fromOriginalValues && other._foreignKey == _foreignKey && _keyComparer.Equals(_keyValue, other._keyValue);