public void RunElasticArray() { var array = new ElasticArray <int>(128); for (int i = 0; i < Size; i++) { array.Add(_nums[i]); } array.Sort(); }
private void Flush() { this.listData = new ElasticArray(); if (this.Type == QueryType.Aggregate) { this.aggregateData = new ElasticArray(); this.aggregateHeader = new List <AggregateAttribute>(); } else if (this.Type != QueryType.List) { throw QueryException.InvalidQueryType(this.Type); } }
public void IndexOutOfBound() { var size = 100; var array = new ElasticArray <int>(size); for (int i = 0; i < size / 2; i++) { array.Add(i * 2); } Assert.Throws <IndexOutOfRangeException>(() => array[size / 2 + 1]); Assert.Throws <IndexOutOfRangeException>(() => array[-1]); Assert.Throws <IndexOutOfRangeException>(() => array[size / 2 + 1] = 33); Assert.Throws <IndexOutOfRangeException>(() => array[-1] = 33); }
private ListFactory CompileBuffer(ListResult result, Expression initialize, Expression writeOne, Expression writeAll) { ParameterExpression[] initArgs = new[] { Arguments.Lists }; ParameterExpression[] writeArgs = new[] { Arguments.DataReader, Arguments.Lists, Arguments.Aggregates, Arguments.Helpers, Arguments.Schema }; ListInternalInitializer initializeFunc = this.Compile <ListInternalInitializer>(initialize, initArgs); ListInternalWriter writeOneFunc = this.Compile <ListInternalWriter>(writeOne, writeArgs); ListInternalWriter writeAllFunc = this.Compile <ListInternalWriter>(writeAll, writeArgs); ElasticArray helpers = this.GetHelperBuffer(result.Helpers); ISchema schema = result.Schema; if (result.QueryType == QueryType.Aggregate) { AggregateAttribute[] header = result.Aggregates.Select(a => a.Attribute).NotNull().ToArray(); return(new ListFactory() { Initialize = buf => { buf.AggregateHeader.AddRange(header); initializeFunc(buf.ListData); }, WriteOne = (buf, dr) => writeOneFunc(dr, buf.ListData, buf.AggregateData, helpers, schema), WriteAll = (buf, dr) => { buf.AggregateHeader.AddRange(header); writeAllFunc(dr, buf.ListData, buf.AggregateData, helpers, schema); }, }); } else { return(new ListFactory() { WriteAll = (buf, dr) => writeAllFunc(dr, buf.ListData, buf.AggregateData, helpers, schema), WriteOne = (buf, dr) => writeOneFunc(dr, buf.ListData, buf.AggregateData, helpers, schema), Initialize = buf => initializeFunc(buf.ListData), }); } }
public void Sort_search() { var rand = new Random(); var size = 100; var array = new ElasticArray <int>(size); for (int i = 0; i < size; i++) { array.Add(rand.Next()); } array.Sort(); for (int i = 1; i < size; i++) { Assert.True(array[i - 1] <= array[i]); } var x = array[5]; Assert.Equal(5, array.BinarySearch(x)); }
public void Add_tests() { var size = 100; var array = new ElasticArray <int>(size); for (int i = 0; i < size; i++) { array.Add(i * 2); } Assert.Equal(size, array.Count); Assert.Equal(2 * 5, array[5]); array[5] = 5; Assert.Equal(5, array[5]); for (int i = 0; i < size / 2; i++) { array.Add(i * 3); } Assert.Equal(size + size / 2, array.Count); Assert.Equal(2 * size, array.Size); }
/// <summary> /// Удаляет связь с дочерним элементом /// </summary> /// <param name="child">Дочерний элемент.</param> protected internal void UnlinkChild(GraphItem child) { if(Object.Equals(_ch, child)) _ch = null; else if(_chs != null) { _chs.Remove(child); if(_chs.Length == 0) _chs = null; else if(_chs.Length == 1) { _ch = _chs[0]; _chs = null; } } }
/// <summary> /// Удаляет связь с родителским элементом /// </summary> /// <param name="parent">Родительский элемент.</param> protected internal void UnlinkParent(GraphItem parent) { if(Object.Equals(_p, parent)) _p = null; else if(_ps != null) { _ps.Remove(parent); if(_ps.Length == 0) _ps = null; else if(_ps.Length == 1) { _p = _ps[0]; _ps = null; } } }
/// <summary> /// Добавляет связь с дочерним элементом в начало списка связей /// </summary> /// <param name="child">Дочерний элемент.</param> protected internal void LinkChildFirst(GraphItem child) { if(_chs != null) _chs.Insert(0, child); else if(_ch == null) _ch = child; else { _chs = new ElasticArray<GraphItem>() {child, _ch }; _ch = null; } }
/// <summary> /// Добавляет связь с дочерним элементом /// </summary> /// <param name="child">Дочерний элемент.</param> protected internal void LinkChild(GraphItem child) { if(_chs != null) _chs.Add(child); else if(_ch == null) _ch = child; else { _chs = new ElasticArray<GraphItem>() { _ch, child }; _ch = null; } }
/// <summary> /// Добавляет связь с родителским элементом /// </summary> /// <param name="parent">Родительский элемент.</param> protected internal void LinkParent(GraphItem parent) { if(_ps != null) _ps.Add(parent); else if(_p == null) _p = parent; else { _ps = new ElasticArray<GraphItem>() { _p, parent }; _p = null; } }
//------------------------------------------------------------------------------------- #region << Protected & Override Methods >> /// <summary> /// Удаляет все дочерние и родительские связи элемента. /// </summary> protected internal void UnlinkItem() { if(IsRoot == false) { foreach(GraphItem i in Parents.ToArray()) i.UnlinkChild(this); _p = null; _ps = null; } if(HasChildren) { foreach(GraphItem i in Children.ToArray()) i.UnlinkParent(this); _ch = null; _chs = null; } }