コード例 #1
0
        private void InitializeIfNecessary(TItem item)
        {
            if (Root != null)
            {
                return;
            }

            Root = new GenericPartitionTreeSection <TBoundary, TItem>(GetSectionBoundary(GetItemPoint(item), InitialPartitionSize));
        }
コード例 #2
0
        protected void RedistributeItemsWithinSubsections(GenericPartitionTreeSection <TBoundary, TItem> section)
        {
            foreach (var item in section.Items)
            {
                FindPointSubsection(section, item)?.AddItem(item);
            }

            section.RemoveItems();
        }
コード例 #3
0
        private void RemoveAllItems(GenericPartitionTreeSection <TBoundary, TItem> root)
        {
            root.RemoveItems();

            foreach (var subsection in root.Subsections)
            {
                RemoveAllItems(subsection);
            }
        }
コード例 #4
0
        private bool HasItem(TItem item, GenericPartitionTreeSection <TBoundary, TItem> root)
        {
            if (root == null)
            {
                return(false);
            }

            return(root.Items.Contains(item) || root.Subsections.Any(subsection => HasItem(item, subsection)));
        }
コード例 #5
0
        protected void AddSubsection(GenericPartitionTreeSection <TBoundary, TItem> root, GenericPartitionTreeSection <TBoundary, TItem> section)
        {
            if (root.SubsectionCount >= SubsectionsPerSection)
            {
                throw new IndexOutOfRangeException();
            }

            section.Parent = root;
            root.AddSubsection(section);
        }
コード例 #6
0
        private IEnumerable <TItem> GetItemsWithinBoundary(TBoundary boundary, GenericPartitionTreeSection <TBoundary, TItem> section)
        {
            var list = new List <TItem>();

            if (!BoundaryContains(section.Boundary, boundary) && !BoundaryIntersects(section.Boundary, boundary))
            {
                return(list);
            }

            if (section.SubsectionCount == 0)
            {
                return(section.Items);
            }

            foreach (var subsection in section.Subsections)
            {
                list.AddRange(GetItemsWithinBoundary(boundary, subsection));
            }

            return(list);
        }
コード例 #7
0
        private GenericPartitionTreeSection <TBoundary, TItem> FindPointSubsection(GenericPartitionTreeSection <TBoundary, TItem> root, TItem item)
        {
            if (!SectionContains(root, item))
            {
                return(null);
            }

            if (root.SubsectionCount == 0)
            {
                return(root);
            }

            foreach (var subsection in root.Subsections)
            {
                var sec = FindPointSubsection(subsection, item);
                if (sec != null)
                {
                    return(sec);
                }
            }

            return(null);
        }
コード例 #8
0
 protected abstract void Subdivide(GenericPartitionTreeSection <TBoundary, TItem> section);
コード例 #9
0
 protected abstract bool SectionContains(GenericPartitionTreeSection <TBoundary, TItem> section, TItem item);
コード例 #10
0
 internal void AddSubsection(GenericPartitionTreeSection <TBoundary, TItem> section)
 {
     _subsections.Add(section);
 }
コード例 #11
0
 private GenericPartitionTreeSection <TBoundary, TItem> GetItemSection(TItem item, GenericPartitionTreeSection <TBoundary, TItem> root)
 {
     return(root.Items.Contains(item) ? root : root.Subsections.Select(subsection => GetItemSection(item, subsection)).FirstOrDefault());
 }
コード例 #12
0
 private bool SectionNeedsSubdividing(GenericPartitionTreeSection <TBoundary, TItem> section)
 {
     return(section.ItemCount >= SectionItemMaxCount);
 }