Click here to Skip to main content
15,891,905 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
// ISetImm and its component interfaces, ISetTests and ISetOperations
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Loyc.Collections
{
	/// <summary>Set testing operations.</summary>
	/// <typeparam name="SetT">Type of set that this set can be tested against.</typeparam>
	public interface ISetTests<SetT>
	{
		bool IsProperSubsetOf(SetT other);
		bool IsProperSupersetOf(SetT other);
		bool IsSubsetOf(SetT other);
		bool IsSupersetOf(SetT other);
		bool Overlaps(SetT other);
		bool SetEquals(SetT other);
	}

	/// <summary>Set-combining operations: With, Without, Union, Intersect, Except, Xor.</summary>
	/// <typeparam name="T">Type of items in the set.</typeparam>
	/// <typeparam name="SetT">Type of the set itself.</typeparam>
	#if CSharp4
	public interface ISetOperations<in T, SetT> : ISetOperations<T, SetT, SetT> { }
	public interface ISetOperations<in T, in InSetT, out OutSetT>
	#else
	public interface ISetOperations<T, SetT> : ISetOperations<T, SetT, SetT> { }
	public interface ISetOperations<T, InSetT, OutSetT>
	#endif
	{
		OutSetT With(T item);
		OutSetT Without(T item);
		OutSetT Union(InSetT other);
		OutSetT Intersect(InSetT other);
		OutSetT Except(InSetT other);
		OutSetT Xor(InSetT other);
	}


	/// <summary>Immutable set operations.</summary>
	/// <typeparam name="SetT">Type of this set.</typeparam>
	/// <typeparam name="T">Type of items in the set</typeparam>
	public interface ISetImm<T, SetT> : ISetOperations<T, SetT>, ISetTests<SetT>, IReadOnlyCollection<T> //ICount
	{
		/// <summary>Returns true if the set is inverted, which means that the
		/// enumerator returns all the items that are <i>not</i> in the set, 
		/// and the <see cref="Count"/> returns the number of items that are
		/// not in the set.</summary>
		/// <remarks><see cref="InvertibleSet{T}"/> is an example of a set that 
		/// can be inverted. In most set implementations, this property always 
		/// returns false.</remarks>
		bool IsInverted { get; }
	}
}

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