public IEnumerable <T> Get(int index) { int?firstObjectIndex = _latestObjectIndex.GetAtIndex(index); if (firstObjectIndex == null) { yield break; } int objectIndex = firstObjectIndex.Value; while (objectIndex != -1) { byte[] data = _objectIndex.GetDataAtIndex(objectIndex); LinkedIndexItem <T>?item = null; if (data != null) { item = LinkedIndexItem <T> .FromArray(data); } if (item != null) { objectIndex = item.Value.PreviousItem; yield return(item.Value.Content); } else { objectIndex = -1; } } }
public static LinkedIndexItem <T> FromArray(byte[] bytes) { BinaryReader reader = new BinaryReader(new MemoryStream(bytes)); LinkedIndexItem <T> s = default(LinkedIndexItem <T>); s.Content = ConverterHelper.FromBytes <T>(reader.ReadBytes(SizeHelper.SizeOf(typeof(T)))); s.PreviousItem = reader.ReadInt32(); return(s); }
public void Add(int index, T content) { lock (_writeLock) { int?locationOfCurrentVersion = _latestObjectIndex.GetAtIndex(index); LinkedIndexItem <T> item = new LinkedIndexItem <T> { Content = content }; item.PreviousItem = locationOfCurrentVersion ?? -1; int itemIndex = _objectIndex.Last() + 1; _objectIndex.SetAtIndex(itemIndex, item.ToArray()); _latestObjectIndex.SetAtIndex(index, itemIndex); } }