Click here to Skip to main content
15,888,521 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>
	/// Provides view of an <see cref="IList{T}"/> in which element [i] is a 
	/// <see cref="NegList{T}"/> N such that N[0] refers to element [i] in the 
	/// original list. See <see cref="LCExt.NegLists{T}(IList{T})"/> for more 
	/// information.
	/// </summary>
	/// <seealso cref="SelectNegListSources{T}"/>
	[Serializable]
	public class SelectNegLists<T> : ListSourceBase<NegList<T>>
	{
		protected IList<T> _list;

		public SelectNegLists(IList<T> list) { _list = list; }

		public IList<T> OriginalList { get { return _list; } }
		
		public sealed override NegList<T> TryGet(int index, ref bool fail)
		{
			fail = (uint)index >= (uint)_list.Count;
			return new NegList<T>(_list, index);
		}
		public sealed override int Count
		{
			get { return _list.Count; }
		}
	}
}

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