コード例 #1
0
ファイル: IndexNode.cs プロジェクト: weihangChen/demoapp
        public int CompareTo(object obj)
        {
            IndexNode <TIndex, TRow> tmp = (IndexNode <TIndex, TRow>)obj;

            if (tmp == null)
            {
                throw new InvalidCastException(string.Format("Object is type: {0} , expected type: {1}", obj.GetType(),
                                                             this.GetType()));
            }

            Type inner = IndexBy.GetType();
            Type outer = tmp.IndexBy.GetType();

            //object value =  Convert.ChangeType(tmp.IndexBy, typeof (TIndex));

            return(IndexBy.CompareTo(tmp.IndexBy));
        }
コード例 #2
0
        //Add a node when a row was added to the table
        internal void AddIndexNode(TRow row)
        {
            ICollection <IndexNode <TIndex, TRow> > indexNodes = FindNodes(PropertyFunc(row), PropertyFunc(row));

            //An indexnode is missing for the property value, need to add new node for that value
            if (indexNodes.Count == 0)
            {
                IndexNode <TIndex, TRow> nodeToAdd = new IndexNode <TIndex, TRow>(PropertyFunc(row));
                nodeToAdd.AddRow(row);
                _tree.Add(nodeToAdd);
            }

            else
            {
                foreach (var indexNode in indexNodes)
                {
                    indexNode.AddRow(row);
                }
            }
        }
コード例 #3
0
        //Initilizing the index by providing the table data to be able to save a reference to the rows
        //and also providing a Function that determine which property will be indexed.
        private void InitIndex(IEnumerable <TRow> tableData)
        {
            //TIndex - Field like Name, Age    TRow - Entity like Person

            var groups = tableData.GroupBy(row => PropertyFunc(row));
            var nodes  = new List <IndexNode <TIndex, TRow> >();

            foreach (var group in groups)
            {
                IndexNode <TIndex, TRow> node = new IndexNode <TIndex, TRow>(PropertyFunc(group.First()));

                foreach (var row in group)
                {
                    node.AddRow(row);
                }

                nodes.Add(node);
            }

            _tree.Add(nodes);
        }