Click here to Skip to main content
15,895,799 members
Articles / General Programming / Performance

B-Tree Sorted Dictionary

Rate me:
Please Sign up or sign in to vote.
4.96/5 (48 votes)
26 Jan 2024MIT8 min read 182.4K   4.8K   140  
In-memory B-Tree sorted dictionary
/* 
 * Copyright(c) 2002 Gerardo Recinto/4A Technologies (http://www.4atech.net)
 */
using System;
using System.Collections.Generic;
using System.Text;

namespace Sop.Collections.Generic.BTree
{
	internal class BTreeValues<TKey, TValue> : System.Collections.Generic.ICollection<TValue>, IEnumerable<TValue>
	{
		public BTreeValues(Sop.Collections.Generic.BTree.BTreeDictionary<TKey, TValue> Dictionary)
		{
			this.Dictionary = Dictionary;
		}
		public void Add(TValue item)
		{
			throw new InvalidOperationException();
		}

		public void Clear()
		{
			throw new InvalidOperationException();
		}

		public bool Contains(TValue item)
		{
			throw new InvalidOperationException();
		}

		public void CopyTo(TValue[] array, int arrayIndex)
		{
			if (array == null)
				throw new ArgumentNullException("array");
			if (arrayIndex < 0 || arrayIndex >= array.Length)
				throw new ArgumentOutOfRangeException("arrayIndex");
			if (Dictionary.Count > array.Length - arrayIndex)
				throw new InvalidOperationException("There are more items to copy than elements on target starting from index");
			if (Dictionary.MoveFirst())
			{
				do
				{
					array[arrayIndex++] = Dictionary.CurrentValue;
				} while (Dictionary.MoveNext());
			}
		}

		public int Count
		{
			get
			{
				return Dictionary.Count;
			}
		}

		public bool IsReadOnly
		{
			get
			{
				return true;
			}
		}

		public bool Remove(TValue item)
		{
			throw new InvalidOperationException();
		}

		public IEnumerator<TValue> GetEnumerator()
		{
			return new BTreeDictionary<TKey, TValue>.BTreeEnumeratorValue(Dictionary);
		}

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return this.GetEnumerator();
		}

        Sop.Collections.Generic.BTree.BTreeDictionary<TKey, TValue> Dictionary;
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
United States United States
Ex Google, ex Microsoft
I'm just fresh off from a software eng'g gig & is looking forward to my next.
Pls. do drop me a line @gerardorecinto@yahoo.com if interested or having any question/feedback on these Open Source projects.

I'm excited to help/volunteer my services.
Have a great day!

Comments and Discussions