Click here to Skip to main content
15,893,487 members
Articles / Programming Languages / C#

The List Trifecta, Part 1

Rate me:
Please Sign up or sign in to vote.
4.97/5 (21 votes)
20 May 2016LGPL321 min read 37.1K   161   40  
The A-list is an all-purpose list, a data structure that can support most standard list operation in O(log n) time and does lots of other stuff, too
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Loyc.Collections
{
	/// <summary>Represents a pool of objects in which an object is
	/// automatically created when requested by its key.</summary>
	/// <typeparam name="TKey">Key type.</typeparam>
	/// <typeparam name="TValue">Value type.</typeparam>
	/// <remarks>This design assumes that the values in the pool know their own 
	/// key, so it implements IEnumerable{TValue} rather than 
	/// IEnumerable{KeyValuePair{TKey,TValue}}.</remarks>
	#if DotNet4
	public interface IAutoCreatePool<in TKey, out TValue> : ISource<TValue>
	#else
	public interface IAutoCreatePool<TKey, TValue> : ISource<TValue>
	#endif
	{
		/// <summary>Gets the item at the specified index.</summary>
		/// <exception cref="ArgumentOutOfRangeException">The index was not valid
		/// in this list.</exception>
		/// <param name="index">An index in the range 0 to Count-1.</param>
		/// <returns>The element at the specified index.</returns>
		TValue this[TKey key] { get; }

		/// <summary>Gets the item with the specified key, if it was created earlier.</summary>
		/// <returns>The value corresponding to the specified key, or default(T) if 
		/// the value has not been created.</returns>
		TValue GetIfExists(TKey key);
	}
}

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 GNU Lesser General Public License (LGPLv3)


Written By
Software Developer None
Canada Canada
Since I started programming when I was 11, I wrote the SNES emulator "SNEqr", the FastNav mapping component, the Enhanced C# programming language (in progress), the parser generator LLLPG, and LES, a syntax to help you start building programming languages, DSLs or build systems.

My overall focus is on the Language of your choice (Loyc) initiative, which is about investigating ways to improve interoperability between programming languages and putting more power in the hands of developers. I'm also seeking employment.

Comments and Discussions