From: Michael D. <mik...@us...> - 2004-11-18 02:40:57
|
Update of /cvsroot/nhibernate/nhibernate/src/Iesi.Collections In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5237/src/Iesi.Collections Added Files: .cvsignore AssemblyInfo.cs DictionarySet.cs HashedSet.cs HybridSet.cs Iesi.Collections-1.1.csproj Iesi.Collections.build Iesi.Collections.license.txt ImmutableSet.cs ISet.cs ListSet.cs NamespaceDoc.cs Set.cs SortedSet.cs SynchronizedSet.cs Log Message: Added code for real implementation of ISet instead of the IDictionary hack we currently use. --- NEW FILE: SynchronizedSet.cs --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Iesi.Collections-1.1.csproj --- <VisualStudioProject> <CSHARP ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{CEF80E5F-E838-4F27-9435-2E3630D5F9E0}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "Iesi.Collections" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" PreBuildEvent = "" PostBuildEvent = "" RootNamespace = "Iesi.Collections" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "" > <Config Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "true" ConfigurationOverrideFile = "" DefineConstants = "DEBUG;TRACE" DocumentationFile = "" DebugSymbols = "true" FileAlignment = "4096" IncrementalBuild = "true" NoStdLib = "false" NoWarn = "" Optimize = "true" OutputPath = "bin\Debug\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> <Config Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "TRACE" DocumentationFile = "" DebugSymbols = "false" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "true" OutputPath = "bin\Release\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" HintPath = "..\..\..\..\WINNT\Microsoft.NET\Framework\v1.0.3705\System.dll" /> <Reference Name = "System.Data" AssemblyName = "System.Data" HintPath = "..\..\..\..\WINNT\Microsoft.NET\Framework\v1.0.3705\System.Data.dll" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" HintPath = "..\..\..\..\WINNT\Microsoft.NET\Framework\v1.0.3705\System.XML.dll" /> </References> </Build> <Files> <Include> <File RelPath = "AssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "DictionarySet.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "HashedSet.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "HybridSet.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Iesi.Collections.build" BuildAction = "None" /> <File RelPath = "ImmutableSet.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "ISet.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "ListSet.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "NamespaceDoc.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Set.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "SortedSet.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "SynchronizedSet.cs" SubType = "Code" BuildAction = "Compile" /> </Include> </Files> </CSHARP> </VisualStudioProject> --- NEW FILE: ISet.cs --- using System; using System.Collections; namespace Iesi.Collections { /// <summary> /// <p>A collection that contains no duplicate elements. This interface models the mathematical /// <c>Set</c> abstraction. /// The order of elements in a set is dependant on (a)the data-structure implementation, and /// (b)the implementation of the various <c>Set</c> methods, and thus is not guaranteed.</p> /// /// <p>None of the <c>Set</c> implementations in this library are guranteed to be thread-safe /// in any way unless wrapped in a <c>SynchronizedSet</c>.</p> /// /// <p>The following table summarizes the binary operators that are supported by the <c>Set</c> class.</p> /// <list type="table"> /// <listheader> /// <term>Operation</term> /// <term>Description</term> /// <term>Method</term> /// </listheader> /// <item> /// <term>Union (OR)</term> /// <term>Element included in result if it exists in either <c>A</c> OR <c>B</c>.</term> /// <term><c>Union()</c></term> /// </item> /// <item> /// <term>Intersection (AND)</term> /// <term>Element included in result if it exists in both <c>A</c> AND <c>B</c>.</term> /// <term><c>InterSect()</c></term> /// </item> /// <item> /// <term>Exclusive Or (XOR)</term> /// <term>Element included in result if it exists in one, but not both, of <c>A</c> and <c>B</c>.</term> /// <term><c>ExclusiveOr()</c></term> /// </item> /// <item> /// <term>Minus (n/a)</term> /// <term>Take all the elements in <c>A</c>. Now, if any of them exist in <c>B</c>, remove /// them. Note that unlike the other operators, <c>A - B</c> is not the same as <c>B - A</c>.</term> /// <term><c>Minus()</c></term> /// </item> /// </list> /// </summary> public interface ISet : ICollection, ICloneable { /// <summary> /// Performs a "union" of the two sets, where all the elements /// in both sets are present. That is, the element is included if it is in either <c>a</c> or <c>b</c>. /// Neither this set nor the input set are modified during the operation. The return value /// is a <c>Clone()</c> of this set with the extra elements added in. /// </summary> /// <param name="a">A collection of elements.</param> /// <returns>A new <c>Set</c> containing the union of this <c>Set</c> with the specified collection. /// Neither of the input objects is modified by the union.</returns> ISet Union(ISet a); /// <summary> /// Performs an "intersection" of the two sets, where only the elements /// that are present in both sets remain. That is, the element is included if it exists in /// both sets. The <c>Intersect()</c> operation does not modify the input sets. It returns /// a <c>Clone()</c> of this set with the appropriate elements removed. /// </summary> /// <param name="a">A set of elements.</param> /// <returns>The intersection of this set with <c>a</c>.</returns> ISet Intersect(ISet a); /// <summary> /// Performs a "minus" of set <c>b</c> from set <c>a</c>. This returns a set of all /// the elements in set <c>a</c>, removing the elements that are also in set <c>b</c>. /// The original sets are not modified during this operation. The result set is a <c>Clone()</c> /// of this <c>Set</c> containing the elements from the operation. /// </summary> /// <param name="a">A set of elements.</param> /// <returns>A set containing the elements from this set with the elements in <c>a</c> removed.</returns> ISet Minus(ISet a); /// <summary> /// Performs an "exclusive-or" of the two sets, keeping only the elements that /// are in one of the sets, but not in both. The original sets are not modified /// during this operation. The result set is a <c>Clone()</c> of this set containing /// the elements from the exclusive-or operation. /// </summary> /// <param name="a">A set of elements.</param> /// <returns>A set containing the result of <c>a ^ b</c>.</returns> ISet ExclusiveOr(ISet a); /// <summary> /// Returns <c>true</c> if this set contains the specified element. /// </summary> /// <param name="o">The element to look for.</param> /// <returns><c>true</c> if this set contains the specified element, <c>false</c> otherwise.</returns> bool Contains(object o); /// <summary> /// Returns <c>true</c> if the set contains all the elements in the specified collection. /// </summary> /// <param name="c">A collection of objects.</param> /// <returns><c>true</c> if the set contains all the elements in the specified collection, <c>false</c> otherwise.</returns> bool ContainsAll(ICollection c); /// <summary> /// Returns <c>true</c> if this set contains no elements. /// </summary> bool IsEmpty{get;} /// <summary> /// Adds the specified element to this set if it is not already present. /// </summary> /// <param name="o">The object to add to the set.</param> /// <returns><c>true</c> is the object was added, <c>false</c> if it was already present.</returns> bool Add(object o); /// <summary> /// Adds all the elements in the specified collection to the set if they are not already present. /// </summary> /// <param name="c">A collection of objects to add to the set.</param> /// <returns><c>true</c> is the set changed as a result of this operation, <c>false</c> if not.</returns> bool AddAll(ICollection c); /// <summary> /// Removes the specified element from the set. /// </summary> /// <param name="o">The element to be removed.</param> /// <returns><c>true</c> if the set contained the specified element, <c>false</c> otherwise.</returns> bool Remove(object o); /// <summary> /// Remove all the specified elements from this set, if they exist in this set. /// </summary> /// <param name="c">A collection of elements to remove.</param> /// <returns><c>true</c> if the set was modified as a result of this operation.</returns> bool RemoveAll(ICollection c); /// <summary> /// Retains only the elements in this set that are contained in the specified collection. /// </summary> /// <param name="c">Collection that defines the set of elements to be retained.</param> /// <returns><c>true</c> if this set changed as a result of this operation.</returns> bool RetainAll(ICollection c); /// <summary> /// Removes all objects from the set. /// </summary> void Clear(); } } --- NEW FILE: NamespaceDoc.cs --- using System; namespace Iesi.Collections { /// <summary> /// <p> /// The System.Collections namespace in the .NET Framework provides a number of collection /// types that are extremely useful for manipulating data in memory. However, there is one /// type of collection that is conspicuously missing from <c>System.Collections</c>: the /// <c>Set</c>. /// </p> /// <p> /// A <c>Set</c> is a collection that contains no duplicate elements, and where the order of /// the elements may be arbitrary. It is loosely modelled after /// the mathematical concept of a "set." This implementation is based on the Java <c>Set</c> /// interface definition, so if you are also a Java programmer, this may seem familiar. /// This library provides a number of "standard" <c>Set</c> operators that the Java library /// neglected to include. /// </p> /// <p> /// <c>Sets</c> come in handy when an <c>Array</c> or a <c>List</c> won't quite fit the bill. /// Arrays in .NET have a fixed length, making it tedious to add and remove elements. /// Lists allow you add new objects easily, but you can have numerous duplicate /// elements, which is undesirable for some types of problems. /// Searching Arrays or Lists for elements is just plain slow for large data sets, /// requiring a linear search. You could keep the array sorted and use a binary search, /// but that is often more trouble than it is worth (especially since this library, /// and the .NET Framework, provide better ways that are already written for you). /// </p> /// <p> /// With sets, adding elements, removing elements, and checking for the existence /// of an element is fast and simple. You can mix and match the elements in different /// sets using the supported mathematical set operators: union, intersection, /// exclusive-or, and minus. /// </p> /// <p> /// You will see some interesting side effects with different <c>Set</c> /// implementations in this library, depending on the underlying search algorithm. /// For example, if you choose a sort-based <c>Set</c>, the elements will come out /// in sort order when you iterate using <c>foreach</c>. If you use a hash-based /// <c>Set</c>, the elements will come out in no particular order, but checking /// for inclusion will fastest when dealing with large data sets. If you use a /// list-based <c>Set</c>, elements will come out in the order you put them in /// when you iterate (although the effect of operators on element order in /// <c>Set</c> instances is not well defined by design). Additionally, list-based /// sets are fastest for very small data sets (up to about 10 elements), /// but get slower very quickly as the number of contained elements increases. /// To get the best of both worlds, the library provides a <c>Set</c> type that /// uses lists for small data sets and switches to a hash-based algorithm when /// the data set gets large enough to warrant it. /// </p> /// <p> /// The following sample program demonstrates some of the features of sets: /// <code> ///using System; ///using Iesi.Collections; ///namespace RiverDemo ///{ /// class Rivers /// { /// [STAThread] /// static void Main(string[] args) /// { /// //Use Arrays (which are ICollection objects) to quickly initialize. /// Set arizona /// = new SortedSet(new string[] {"Colorado River"}); /// Set california /// = new SortedSet(new string[] {"Colorado River", "Sacramento River"}); /// Set colorado /// = new SortedSet(new string[] {"Arkansas River", "Colorado River", "Green River", "Rio Grande"}); /// Set kansas /// = new SortedSet(new string[] {"Arkansas River", "Missouri River"}); /// Set nevada /// = new SortedSet(new string[] {"Colorado River"}); /// Set newMexico /// = new SortedSet(new string[] {"Rio Grande"}); /// Set utah /// = new SortedSet(new string[] {"Colorado River", "Green River", "San Juan River"}); /// //Rivers by region. /// Set southWest = colorado | newMexico | arizona | utah; /// Set midWest = kansas; /// Set west = california | nevada; /// //All rivers (at least for the demo). /// Set all = southWest | midWest | west; /// Print("All rivers:", all); /// Print("Rivers in the southwest:", southWest); /// Print("Rivers in the west:", west); /// Print("Rivers in the midwest:", midWest); /// Console.WriteLine(); /// /// //Use the '-' operator to subtract the rivers in Colorado from /// //the set of all rivers. /// Print("Of all rivers, these don't pass through Colorado:", all - colorado); /// /// //Use the '&' operator to find rivers that are in Colorado AND in Utah. /// //A river must be present in both states, not just one. /// Print("Rivers common to both Colorado and Utah:", colorado & utah); /// /// //use the '^' operator to find rivers that are in Colorado OR Utah, /// //but not in both. /// Print("Rivers in Colorado and Utah that are not shared by both states:", /// colorado ^ utah); /// /// //Use the '&' operator to discover which rivers are present in Arizona, /// // California,Colorado, Nevada, and Utah. The river must be present in /// // all states to be counted. /// Print("Rivers common to Arizona, California, Colorado, Nevada, and Utah:", /// arizona & california & colorado & nevada & utah); /// //Just to prove to you that operators always return like types, let's do a /// //complex Set operation and look at the type of the result: /// Console.WriteLine("The type of this complex operation is: " + /// ((southWest ^ colorado & california) | kansas).GetType().FullName); /// } /// private static void Print(string title, Set elements) /// { /// Console.WriteLine(title); /// foreach(object o in elements) /// { /// Console.WriteLine("\t" + o); /// Console.WriteLine(); /// } /// } /// } /// </code> /// </p> /// <p> /// Although there are other kinds of sets available in the library, the example uses /// <c>SortedSet</c> throughout. This is nice for the example, since everything will /// print neatly in alphabetical order. But you may be wondering what kind of <c>Set</c> /// is returned when you "union," "intersect," "exclusive-or," or "minus" two <c>Set</c> /// instances. The library always returns a <c>Set</c> that is the same type as /// the <c>Set</c> on the left, unless the left operand is null, in which case it /// returns the type of the <c>Set</c> on the right. /// </p> /// <p> /// Here is the output from running the example: /// <code> ///All rivers: ///Arkansas River ///Colorado River ///Green River ///Missouri River ///Rio Grande ///Sacramento River ///San Juan River /// ///Rivers in the southwest: ///Arkansas River ///Colorado River ///Green River ///Rio Grande ///San Juan River /// ///Rivers in the west: ///Colorado River ///Sacramento River /// ///Rivers in the midwest: ///Arkansas River ///Missouri River /// ///Of all rivers, these don't pass through Colorado: ///Missouri River ///Sacramento River ///San Juan River /// ///Rivers common to both Colorado and Utah: ///Colorado River ///Green River /// ///Rivers in Colorado and Utah that are not shared by both states: ///Arkansas River ///Rio Grande ///San Juan River /// ///Rivers common to Arizona, California, Colorado, Nevada, and Utah: ///Colorado River /// ///The type of this complex operation is: ///Iesi.Collections.SortedSet ///Press any key to continue /// </code> /// </p> /// </summary> internal sealed class NamespaceDoc { } } --- NEW FILE: ListSet.cs --- (This appears to be a binary file; contents omitted.) --- NEW FILE: ImmutableSet.cs --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Set.cs --- (This appears to be a binary file; contents omitted.) --- NEW FILE: AssemblyInfo.cs --- using System.Reflection; using System.Runtime.CompilerServices; //------------------------------------------------------------------------------ // <autogenerated> // This code was generated by a tool. // Runtime Version: 1.1.4322.573 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </autogenerated> //------------------------------------------------------------------------------ [assembly: AssemblyTitleAttribute("Iesi.Collections for Microsoft .NET Framework 1.1")] [assembly: AssemblyDescriptionAttribute("Enhanced Collections for .NET. Code was published at http://www.codeproject.com/" + "csharp/sets.asp")] [assembly: AssemblyCompanyAttribute("nhibernate.sourceforge.net")] [assembly: AssemblyProductAttribute("Iesi.Collections")] [assembly: AssemblyCopyrightAttribute("Declaration of code in public domain can be found in comment by Jason Smith at ht" + "tp://www.codeproject.com/csharp/sets.asp#xx703510xx. Copyright © 2002-2004 by A" + "idant Systems, Inc., and by Jason Smith.")] [assembly: AssemblyVersionAttribute("1.0.0.1")] [assembly: AssemblyInformationalVersionAttribute("1.0")] [assembly: AssemblyFileVersionAttribute("1.0.0.1")] [assembly: AssemblyKeyFileAttribute("..\\NHibernate.snk")] --- NEW FILE: Iesi.Collections.build --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Iesi.Collections.license.txt --- (This appears to be a binary file; contents omitted.) --- NEW FILE: HashedSet.cs --- (This appears to be a binary file; contents omitted.) --- NEW FILE: SortedSet.cs --- (This appears to be a binary file; contents omitted.) --- NEW FILE: DictionarySet.cs --- (This appears to be a binary file; contents omitted.) --- NEW FILE: .cvsignore --- bin obj .#* *.user *.xsx --- NEW FILE: HybridSet.cs --- (This appears to be a binary file; contents omitted.) |