Beispiel #1
0
            private void getnextnode()
            {
                recordIndex     = -1;
                recordlistcount = 0;
                recordlist.Clear();
                newRecordList.Clear();

                if (this.currentnode.TreeNode.DiskPosition == this.endnode.TreeNode.DiskPosition)
                {
                    return;
                }

                if (ascending)
                {
                    this.currentnode = MemoryTreeNodeManager.FindNextLeaf(this.treefile, currentnode);
                }
                else
                {
                    this.currentnode = MemoryTreeNodeManager.FindPreviousLeaf(this.treefile, currentnode);
                }

                if (this.currentnode == null)
                {
                    return;
                }

                if (this.currentnode.TreeNode.DiskPosition == this.startnode.TreeNode.DiskPosition)
                {
                    this.isCurrentStartNode = true;
                }
                else
                {
                    this.isCurrentStartNode = false;
                }

                if (this.currentnode.TreeNode.DiskPosition == this.endnode.TreeNode.DiskPosition)
                {
                    this.isCurrentEndNode = true;
                }
                else
                {
                    this.isCurrentEndNode = false;
                }

                if (ascending)
                {
                    loadNodeRecord(currentnode);
                }
                else
                {
                    loadNodeRecordDESC(currentnode);
                }
            }
Beispiel #2
0
            private void init()
            {
                if (ascending)
                {
                    this.startnode = MemoryTreeNodeManager.FindLeafByKey(this.treefile, this.treefile.RootCache, startKeyBytes);
                    this.endnode   = MemoryTreeNodeManager.FindLeafByKey(this.treefile, this.treefile.RootCache, endKeyBytes);
                }
                else
                {
                    //load the last key as startnode, firstkey as endnode.
                    this.endnode   = MemoryTreeNodeManager.FindLeafByKey(this.treefile, this.treefile.RootCache, startKeyBytes);
                    this.startnode = MemoryTreeNodeManager.FindLeafByKey(this.treefile, this.treefile.RootCache, endKeyBytes);
                }

                this.currentnode = startnode;
                if (currentnode == null)
                {
                    return;
                }

                isCurrentStartNode = true;

                if (currentnode.TreeNode.DiskPosition == endnode.TreeNode.DiskPosition)
                {
                    isCurrentEndNode = true;
                }
                recordIndex     = -1;
                recordlistcount = 0;

                if (ascending)
                {
                    loadNodeRecord(currentnode);
                }
                else
                {
                    loadNodeRecordDESC(currentnode);
                }
            }
Beispiel #3
0
        /// <summary>
        /// Get the count of records in the range. count distinct will have better performance.
        /// </summary>
        /// <param name="range"></param>
        /// <param name="distinct"></param>
        /// <returns></returns>
        public int Count(Range <T> range, bool distinct)
        {
            lock (_object)
            {
                byte[] startKeyBytes = this.Converter.ToByte(range.lower);
                byte[] endKeyBytes   = this.Converter.ToByte(range.upper);

                startKeyBytes = this.appendToFixedLength(startKeyBytes);
                endKeyBytes   = this.appendToFixedLength(endKeyBytes);

                MemoryTreeNode startnode = MemoryTreeNodeManager.FindLeafByKey(this.Tree, this.Tree.RootCache, startKeyBytes);
                MemoryTreeNode endnode   = MemoryTreeNodeManager.FindLeafByKey(this.Tree, this.Tree.RootCache, endKeyBytes);

                if (startnode.TreeNode.DiskPosition == endnode.TreeNode.DiskPosition)
                {
                    int count = 0;
                    foreach (var item in startnode.TreeNode.KeyArray)
                    {
                        if ((this.Comparer.Compare(startKeyBytes, item.Key) < 0 || (this.Comparer.Compare(startKeyBytes, item.Key) == 0 && !range.lowerOpen)) && ((this.Comparer.Compare(endKeyBytes, item.Key) > 0 || (this.Comparer.Compare(endKeyBytes, item.Key) == 0 && !range.upperOpen))))
                        {
                            if (!distinct)
                            {
                                NodePointer pointer = new NodePointer();
                                pointer.PointerBytes = item.Value;

                                if (pointer.Indicator == EnumValues.TypeIndicator.duplicate)
                                {
                                    count = count + this.Tree.duplicate.count(pointer.PositionPointer);
                                }
                                else
                                {
                                    count += 1;
                                }
                            }
                            else
                            {
                                count += 1;
                            }
                        }
                    }
                    return(count);
                }
                else
                {
                    int firstnodecount = 0;
                    int lastnodecount  = 0;
                    int middlecount    = 0;

                    foreach (var item in startnode.TreeNode.KeyArray)
                    {
                        if (this.Comparer.Compare(startKeyBytes, item.Key) < 0 || (this.Comparer.Compare(startKeyBytes, item.Key) == 0 && !range.lowerOpen))
                        {
                            if (!distinct)
                            {
                                NodePointer pointer = new NodePointer();
                                pointer.PointerBytes = item.Value;

                                if (pointer.Indicator == EnumValues.TypeIndicator.duplicate)
                                {
                                    firstnodecount = firstnodecount + this.Tree.duplicate.count(pointer.PositionPointer);
                                }
                                else
                                {
                                    firstnodecount += 1;
                                }
                            }
                            else
                            {
                                firstnodecount += 1;
                            }
                        }
                    }

                    foreach (var item in endnode.TreeNode.KeyArray)
                    {
                        if (this.Comparer.Compare(endKeyBytes, item.Key) > 0 || (this.Comparer.Compare(endKeyBytes, item.Key) == 0 && !range.upperOpen))
                        {
                            if (!distinct)
                            {
                                NodePointer pointer = new NodePointer();
                                pointer.PointerBytes = item.Value;

                                if (pointer.Indicator == EnumValues.TypeIndicator.duplicate)
                                {
                                    lastnodecount = lastnodecount + this.Tree.duplicate.count(pointer.PositionPointer);
                                }
                                else
                                {
                                    lastnodecount += 1;
                                }
                            }
                            else
                            {
                                lastnodecount += 1;
                            }
                        }
                    }

                    var middlenode = MemoryTreeNodeManager.FindNextLeaf(this.Tree, startnode);

                    while (middlenode.TreeNode.DiskPosition != endnode.TreeNode.DiskPosition)
                    {
                        foreach (var item in middlenode.TreeNode.KeyArray)
                        {
                            if (!distinct)
                            {
                                NodePointer pointer = new NodePointer();
                                pointer.PointerBytes = item.Value;

                                if (pointer.Indicator == EnumValues.TypeIndicator.duplicate)
                                {
                                    middlecount = middlecount + this.Tree.duplicate.count(pointer.PositionPointer);
                                }
                                else
                                {
                                    middlecount += 1;
                                }
                            }
                            else
                            {
                                middlecount += 1;
                            }
                        }

                        middlenode = MemoryTreeNodeManager.FindNextLeaf(this.Tree, middlenode);
                    }

                    return(firstnodecount + middlecount + lastnodecount);
                }
            }
        }