public void TestSizeConstructor() { var list = new LargeList <Int32>(1); list.Add(1); Assert.AreEqual(list.Count, 1); foreach (var item in list) { Assert.AreEqual(item, 1); } var size = (1 << 14) + 1; list = new LargeList <Int32>(size); for (int i = 0; i < size * 2; i++) { list.Add(i); } for (int i = 0; i < size * 2; i++) { Assert.AreEqual(list[i], i); } }
public void TestInsertRangeWithExistingItems() { var list = new LargeList <Int32>(); var size = (1 << 16) + 2222; var oneThird = size / 3; for (int i = 0; i < oneThird; i++) { list.Add(i); } for (int i = 2 * oneThird; i < 3 * oneThird; i++) { list.Add(i); } var helperArray = new Int32[oneThird]; for (int i = oneThird; i < 2 * oneThird; i++) { helperArray[i - oneThird] = i; } list.InsertRange(oneThird, helperArray); for (int i = 0; i < 3 * oneThird; i++) { Assert.AreEqual(list[i], i); } }
public void FilterLargeList() { if (!args.ValidateLDT()) { return; } Key key = new Key(args.ns, args.set, "setkey"); // Delete record if it already exists. client.Delete(null, key); // Initialize large set operator. LargeList llist = client.GetLargeList(null, key, binName); int orig1 = 1; int orig2 = 2; int orig3 = 3; int orig4 = 4; // Write values. llist.Add(Value.Get(orig1), Value.Get(orig2), Value.Get(orig3), Value.Get(orig4)); // Filter on values IList filterList = llist.Filter("largelist_example", "my_filter_func", Value.Get(orig3)); Assert.IsNotNull(filterList); Assert.AreEqual(1, filterList.Count); long v = (long)filterList[0]; Assert.AreEqual(orig3, (int)v); }
public void Select_LargeList_Throws_ArgumentOutOfRange() { var largeList = new LargeList(); Assert.Throws <ArgumentOutOfRangeException>(() => Socket.Select(largeList, null, null, -1)); Assert.Throws <ArgumentOutOfRangeException>(() => Socket.Select(null, largeList, null, -1)); Assert.Throws <ArgumentOutOfRangeException>(() => Socket.Select(null, null, largeList, -1)); }
public override void Write(int flowID, IEnumerable <KeyValuePair <long, STS.General.Generators.Tick> > flow) { LargeList index = indexes[flowID]; foreach (var kv in flow) { index.Update(Value.Get(kv.ToString())); } }
private LargeList <Int32> CreateList(int size) { var list = new LargeList <Int32>(); for (int i = 0; i < size; i++) { list.Add(i); } return(list); }
public void TestInsert() { var list = new LargeList <Int32>(); list.Insert(0, 0); list.Add(2); list.Insert(1, 1); for (int i = 0; i < 3; i++) { Assert.AreEqual(i, list[i]); } }
public void RunVolumeInsert() { // This key has already been created in runSimpleExample(). Key key = new Key(args.ns, args.set, "setkey"); int itemCount = 2000; LargeList llist2 = client.GetLargeList(null, key, "NumberBin"); for (int i = itemCount; i > 0; i--) { llist2.Add(Value.Get(i)); } Assert.AreEqual(2000, llist2.Size()); }
public void Select_LargeList_Throws_ArgumentOutOfRange_TimeSpan() { var largeList = new LargeList(); TimeSpan infinity = Timeout.InfiniteTimeSpan; Assert.Throws <ArgumentOutOfRangeException>(() => Socket.Select(largeList, null, null, infinity)); Assert.Throws <ArgumentOutOfRangeException>(() => Socket.Select(null, largeList, null, infinity)); Assert.Throws <ArgumentOutOfRangeException>(() => Socket.Select(null, null, largeList, infinity)); TimeSpan negative = TimeSpan.FromMilliseconds(-1); Assert.Throws <ArgumentOutOfRangeException>(() => Socket.Select(largeList, null, null, negative)); Assert.Throws <ArgumentOutOfRangeException>(() => Socket.Select(null, largeList, null, negative)); Assert.Throws <ArgumentOutOfRangeException>(() => Socket.Select(null, null, largeList, negative)); }
public void SimpleLargeList() { Key key = new Key(args.ns, args.set, "setkey"); // Delete record if it already exists. client.Delete(null, key); // Initialize large set operator. LargeList llist = client.GetLargeList(null, key, binName); string orig1 = "llistValue1"; string orig2 = "llistValue2"; string orig3 = "llistValue3"; // Write values. llist.Add(Value.Get(orig1)); llist.Add(Value.Get(orig2)); llist.Add(Value.Get(orig3)); // Perform a Range Query -- look for "llistValue2" to "llistValue3" IList rangeList = llist.Range(Value.Get(orig2), Value.Get(orig3)); Assert.IsNotNull(rangeList); Assert.AreEqual(2, rangeList.Count); string v2 = (string)rangeList[0]; string v3 = (string)rangeList[1]; Assert.AreEqual(orig2, v2); Assert.AreEqual(orig3, v3); // Remove last value. llist.Remove(Value.Get(orig3)); int size = llist.Size(); Assert.AreEqual(2, size); IList listReceived = llist.Find(Value.Get(orig2)); string expected = orig2; Assert.IsNotNull(listReceived); string stringReceived = (string)listReceived[0]; Assert.IsNotNull(stringReceived); Assert.AreEqual(expected, stringReceived); }
public void TestEnumerator() { var list = new LargeList <Int32>(); var size = 1 << 20; var helperArray = new int[size]; for (int i = 0; i < size; i++) { list.Add(i); helperArray[i] = i; } foreach (var num in list) { Assert.AreEqual(num, helperArray[num]); } }
public void TestEnumerableConsuctor() { var size = (1 << 14) + 2500; var array = new Int32[size]; for (int i = 0; i < size; i++) { array[i] = i; } var list = new LargeList <Int32>(array); for (int i = 0; i < size; i++) { Assert.AreEqual(array[i], list[i]); } }
public void TestInsertRangeInEmptyList() { var list = new LargeList <Int32>(); var size = (1 << 14) + 123; var helperArray = new Int32[size]; for (int i = 0; i < size; i++) { helperArray[i] = i; } list.InsertRange(0, helperArray); for (int i = 0; i < size; i++) { Assert.AreEqual(helperArray[i], list[i]); } }
public void TestSort() { var size = (1 << 14) + 1234; var list = new LargeList <Int32>(); var helperArray = new Int32[size]; var random = new Random(); for (int i = 0; i < size; i++) { var n = random.Next(); helperArray[i] = n; list.Add(n); } Array.Sort(helperArray); list.Sort(); for (int i = 0; i < size; i++) { Assert.AreEqual(helperArray[i], list[i]); } }
public override IEnumerable <KeyValuePair <long, STS.General.Generators.Tick> > Read() { LargeList index = indexes[0]; foreach (string value in index.Scan()) { string[] str = value.Remove(0, 1).Remove(value.Length - 2, 1).Split(','); // remove '[' ']' long key = long.Parse(str[0]); str = str[1].Split(';'); string symbol = str[0]; DateTime time = DateTime.Parse(str[1]); double bid = double.Parse(str[2]); double ask = double.Parse(str[3]); int bidSize = int.Parse(str[4]); int askSize = int.Parse(str[5]); string provider = str[6]; Tick tick = new Tick(symbol, time, bid, ask, bidSize, askSize, provider); yield return(new KeyValuePair <long, Tick>(key, tick)); } }
public void SimpleLargeList() { if (!args.ValidateLDT()) { return; } Key key = new Key(args.ns, args.set, "setkey"); // Delete record if it already exists. client.Delete(null, key); // Initialize large set operator. LargeList llist = client.GetLargeList(null, key, binName); string orig1 = "llistValue1"; string orig2 = "llistValue2"; string orig3 = "llistValue3"; // Write values. llist.Add(Value.Get(orig1)); llist.Add(Value.Get(orig2)); llist.Add(Value.Get(orig3)); // Perform exists. bool b = llist.Exists(Value.Get(orig2)); Assert.IsTrue(b); b = llist.Exists(Value.Get("notfound")); Assert.IsFalse(b); // Test record not found. LargeList nflist = client.GetLargeList(null, new Key(args.ns, args.set, "sfdfdqw"), binName); b = nflist.Exists(Value.Get(orig2)); Assert.IsFalse(b); IList klist = new List <Value>(); klist.Add(Value.Get(orig2)); klist.Add(Value.Get(orig1)); klist.Add(Value.Get("notfound")); IList <bool> blist = llist.Exists(klist); Assert.IsTrue(blist[0]); Assert.IsTrue(blist[1]); Assert.IsFalse(blist[2]); // Test record not found. IList <bool> blist2 = nflist.Exists(klist); Assert.IsFalse(blist2[0]); Assert.IsFalse(blist2[1]); Assert.IsFalse(blist2[2]); // Perform a Range Query -- look for "llistValue2" to "llistValue3" IList rangeList = llist.Range(Value.Get(orig2), Value.Get(orig3)); Assert.IsNotNull(rangeList); Assert.AreEqual(2, rangeList.Count); string v2 = (string)rangeList[0]; string v3 = (string)rangeList[1]; Assert.AreEqual(orig2, v2); Assert.AreEqual(orig3, v3); // Remove last value. llist.Remove(Value.Get(orig3)); int size = llist.Size(); Assert.AreEqual(2, size); IList listReceived = llist.Find(Value.Get(orig2)); string expected = orig2; Assert.IsNotNull(listReceived); string stringReceived = (string)listReceived[0]; Assert.IsNotNull(stringReceived); Assert.AreEqual(expected, stringReceived); }
public void RunWithSerializedBin() { if (!args.ValidateLDT()) { return; } Key key = new Key(args.ns, args.set, "accountId"); // Delete record if it already exists. client.Delete(null, key); // Initialize large list operator. LargeList list = client.GetLargeList(null, key, "trades"); // Write trades Dictionary <string, Value> map = new Dictionary <string, Value>(); MemoryStream ms = new MemoryStream(500); DateTime timestamp1 = new DateTime(2014, 6, 25, 12, 18, 43); map["key"] = Value.Get(timestamp1.Ticks); BinaryWriter writer = new BinaryWriter(ms); writer.Write("IBM"); // ticker writer.Write(100); // qty writer.Write(181.82); // price map["value"] = Value.Get(ms.ToArray()); list.Add(Value.Get(map)); DateTime timestamp2 = new DateTime(2014, 6, 26, 9, 33, 17); map["key"] = Value.Get(timestamp2.Ticks); ms.SetLength(0); writer = new BinaryWriter(ms); writer.Write("GE"); // ticker writer.Write(500); // qty writer.Write(26.36); // price map["value"] = Value.Get(ms.ToArray()); list.Add(Value.Get(map)); DateTime timestamp3 = new DateTime(2014, 6, 27, 14, 40, 19); map["key"] = Value.Get(timestamp3.Ticks); ms.SetLength(0); writer = new BinaryWriter(ms); writer.Write("AAPL"); // ticker writer.Write(75); // qty writer.Write(91.85); // price map["value"] = Value.Get(ms.ToArray()); list.Add(Value.Get(map)); // Verify list size int size = list.Size(); Assert.AreEqual(3, size); // Filter on range of timestamps DateTime begin = new DateTime(2014, 6, 26); DateTime end = new DateTime(2014, 6, 28); IList results = list.Range(Value.Get(begin.Ticks), Value.Get(end.Ticks)); Assert.IsNotNull(results); Assert.AreEqual(2, results.Count); // Verify data. ValidateWithSerializedBin(results, 0, timestamp2, "GE", 500, 26.36); ValidateWithSerializedBin(results, 1, timestamp3, "AAPL", 75, 91.85); }
public void DistinctBinsLargeList() { if (!args.ValidateLDT()) { return; } Key key = new Key(args.ns, args.set, "accountId"); // Delete record if it already exists. client.Delete(null, key); // Initialize large list operator. LargeList list = client.GetLargeList(null, key, "trades"); // Write trades Dictionary <string, Value> map = new Dictionary <string, Value>(); DateTime timestamp1 = new DateTime(2014, 6, 25, 12, 18, 43); map["key"] = Value.Get(timestamp1.Ticks); map["ticker"] = Value.Get("IBM"); map["qty"] = Value.Get(100); map["price"] = Value.Get(BitConverter.GetBytes(181.82)); list.Add(Value.Get(map)); DateTime timestamp2 = new DateTime(2014, 6, 26, 9, 33, 17); map["key"] = Value.Get(timestamp2.Ticks); map["ticker"] = Value.Get("GE"); map["qty"] = Value.Get(500); map["price"] = Value.Get(BitConverter.GetBytes(26.36)); list.Add(Value.Get(map)); DateTime timestamp3 = new DateTime(2014, 6, 27, 14, 40, 19); map["key"] = Value.Get(timestamp3.Ticks); map["ticker"] = Value.Get("AAPL"); map["qty"] = Value.Get(75); map["price"] = Value.Get(BitConverter.GetBytes(91.85)); list.Add(Value.Get(map)); // Verify list size int size = list.Size(); Assert.AreEqual(3, size); // Filter on range of timestamps DateTime begin = new DateTime(2014, 6, 26); DateTime end = new DateTime(2014, 6, 28); IList results = list.Range(Value.Get(begin.Ticks), Value.Get(end.Ticks)); Assert.IsNotNull(results); Assert.AreEqual(2, results.Count); // Verify data. ValidateWithDistinctBins(results, 0, timestamp2, "GE", 500, 26.36); ValidateWithDistinctBins(results, 1, timestamp3, "AAPL", 75, 91.85); IList rows = list.Scan(); foreach (IDictionary row in rows) { foreach (DictionaryEntry entry in row) { //console.Info(entry.Key.ToString()); //console.Info(entry.Value.ToString()); } } }
public void Select_LargeList_Throws_ArgumentOutOfRange() { var largeList = new LargeList(); Assert.Throws<ArgumentOutOfRangeException>(() => Socket.Select(largeList, null, null, -1)); Assert.Throws<ArgumentOutOfRangeException>(() => Socket.Select(null, largeList, null, -1)); Assert.Throws<ArgumentOutOfRangeException>(() => Socket.Select(null, null, largeList, -1)); }
public override void Reload() { if (SourceData == null) { string[] Lines = new string[0]; if (Shared.Storage.FileExists(Local)) { Lines = Shared.Storage.GetString(Local).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); } else if (PhaseTable != null) { if (PhaseTable.Table == null) { SourceData = new List <NameValue <string> >(); } else { Lines = Encoding.UTF8.GetString(PhaseTable.Table).Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); } } if (Lines.Any()) { SourceData = Lines .Where(x => x.Contains(',')) .Select(x => { string[] s = x.Split(new char[] { ',' }, 2, StringSplitOptions.RemoveEmptyEntries); return(new NameValue <string>(s[0], s[1])); }).ToList(); } if (SourceData == null) { return; } } LargeList <NameValue <string> > Results = null; if (!string.IsNullOrEmpty(Search)) { if (Search[0] == '^') { string HSearch = Search.Substring(1); if (!string.IsNullOrEmpty(HSearch)) { Results = new LargeList <NameValue <string> >(SourceData.Where(x => x.Name.IndexOf(HSearch) == 0 || x.Value.IndexOf(HSearch) == 0)); } } else if (Search[Search.Length - 1] == '$') { string RSearch = Search.Substring(0, Search.Length - 1); if (!string.IsNullOrEmpty(RSearch)) { int RLen = RSearch.Length; Results = new LargeList <NameValue <string> >(SourceData.Where(x => { int RIndex = x.Name.Length - RLen; if (0 < RIndex && x.Name.IndexOf(RSearch) == RIndex) { return(true); } RIndex = x.Value.Length - RLen; if (0 < RIndex && x.Value.IndexOf(RSearch) == RIndex) { return(true); } return(false); })); } } else { Results = new LargeList <NameValue <string> >(SourceData.Where(x => x.Name.Contains(Search) || x.Value.Contains(Search))); } } else { Results = new LargeList <NameValue <string> >(SourceData); } Observables <NameValue <string>, GRRow <NameValue <string> > > ItemsObservable = new Observables <NameValue <string>, GRRow <NameValue <string> > >(); if (Results != null) { ItemsObservable.ConnectLoader(Results, x => x.Remap(ToGRRow)); } ConvTable.Items = ItemsObservable; }