|
|
Comments and Discussions
|
|
 |
|

|
Hello,
I have a question regarding to the license of the Iesi.Collections. We need to know if we have to mention the usage of your component in our own product description or if we have to fulfill any other requirements regarding your licensing model. It would be very nice if you can give me information to this topic. Under which license does the project run?
Thanks in advance!
Best regards,
Thorsten
|
|
|
|
|
|

|
If you're now using .NET 3.5, the HashSet class will give you high performance set operations.
|
|
|
|

|
I have converted the entire library to used type arguments (i.e. Set). If anyone wants to use that code, email me (christopher@ezln23.com)
|
|
|
|

|
I've been using your Set classes for while now. It's very well done has been very useful, Thanks for your work.
I've recently upgraded to VS2005 and added a nice feature to the Set source code to assist in debugging. The addition is quite simple:
In DictionarySet, add the following lines right before the class definition:
[DebuggerTypeProxy(typeof(DictionarySet.DictionarySetDebugView))]
[DebuggerDisplay("Count = {Count}")]
Then add the following inner class to DictionarySet:
private class DictionarySetDebugView {
private IDictionary dictonary;
public DictionarySetDebugView(DictionarySet dictionarySet) {
if (dictionarySet == null) {
throw new ArgumentNullException("dictionarySet");
}
dictonary = dictionarySet.InternalDictionary;
}
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
public object[] Items {
get {
object[] items = new object[dictonary.Count];
dictonary.Keys.CopyTo(items, 0);
return items;
}
}
}
This will result in the follwoing view in a debugger:
- s Count = 2 Iesi.Collections.ISet {Iesi.Collections.SortedSet}
[0] 1 int
[1] 2 int
+ Raw View
Where s in a SortedSet that I added the integer values 1 & 2.
You might need to add a few #ifdef's to backwards support VS2003, I didn't bother testing on that system.
|
|
|
|

|
Hi Jason,
I was wondering if I could use this code in a project of my own. I'll leave all copyright messages in place.
I was wondering under which licensing terms I can do this? BSD? GPL? anything else?
I need to know because I have indicate this to my superiors.
-Matthias
|
|
|
|

|
You may use this code in your own project. It wouldn't be very useful if you couldn't, now would it?
Honestly though, this is just unmaintained sample code as far as I am concerned. Sorry I put those copyright notices in there. You have my permission to remove them.
The only legal thing is that if you use this code, it is yours. Add it to your project and whittle away. You can change it in any way you like, you can maintain it, and if something is wrong with it, you can fix it.
In other words, there are no licensing terms. Give it away, sell it, repackage it, whatever. Even take credit for writing it if you need to. And that goes for anyone.
And if you really need licensing terms, suggest one here and I'll make that one the official one, or something like that. I know how "superiors" can be.
|
|
|
|

|
I'm using ISet in the 1.1 .NET Framework and with NHibernate.
I tried to use XmlSerializer to serialize an NHibernate object that had a collection of type ISet and received the following exception:
[InvalidOperationException: You must implement a default accessor on Iesi.Collections.ISet because it inherits from ICollection.]
System.Xml.Serialization.TypeScope.GetCollectionElementType(Type type) +580
System.Xml.Serialization.TypeScope.ImportTypeDesc(Type type, Boolean canBePrimitive, MemberInfo memberInfo) +549
System.Xml.Serialization.TypeScope.GetTypeDesc(Type type, MemberInfo source, Boolean directReference) +50
System.Xml.Serialization.StructModel.GetPropertyModel(PropertyInfo propertyInfo) +57
System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo memberInfo) +88
System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns) +1534
System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns) +654
System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, Boolean repeats) +442
I'm not sure quite how to work around this. I did find this article which seems to describe how to properly build a collection class such that it can be serialized with XmlSerializer: http://www.topxml.com/xmlserializer/serializing_collection_classes.asp
Any hints on how to approach this?
Thanks
|
|
|
|

|
i had a similar requirement, seems like the ISet classes in Iesi namespace does not have indexer and the Add methods (strongly-typed). My teammate currently did a manual serialization per field just to make this work but i'm open for any suggestions on how to properly make this work.
(x-a)(x-b)(x-c)...(x-z)
|
|
|
|

|
Hi,
I'm currently facing the same probleme.
Have you found a fix for this?
Thanks.
Christophe.
|
|
|
|

|
C5 is a library of generic collection classes for C# and other CLI languages.
C5 provides functionality and data structures not provided by the standard .Net System.Collections.Generic namespace, such as sets and bags, persistent tree data structures, heap based priority queues, hash indexed array lists and linked lists, and events on collection changes. Also, it is more comprehensive than collection class libraries on other similar platforms, such as Java. Unlike many other collection class libraries, C5 is designed with a strict policy of supporting "code to interface not implementation".
C5 is available in binary and source form under a liberal BSD-style license
and is thoroughly documented in an accompanying free book.
See http://www.itu.dk/research/c5/
|
|
|
|

|
This one is the best as far as I know. I think NHibernate 2.0 should use this.
|
|
|
|

|
In the set class, the method ExclusiveOr was writen as follow
public static ISet ExclusiveOr(ISet a, ISet b)
{
if(a == null && b == null)
return null;
else if(a == null)
return (Set)b.Clone();
else if(b == null)
return (Set)a.Clone();
else
return a.ExclusiveOr(b);
}
Note that the clones of a and b were uneccessarily down cast to Set, while in the Union method of this class, these two clones are down cast to ISet. Although this won't affect any current usage, but for people who wants to have their own implementations of ISet ( an example[^]), this could be a problem.
I did try modify the code to
return (ISet)b.Clone();
...
return (ISet)a.Clone();
And all the Unit Tests from Nhibernate were passed
|
|
|
|

|
Based on Jason and other's work, I just posted a geneic ISet and several implementations:
http://www.codeproject.com/useritems/GenericISet.asp[^]
It passed all the test. I will keep working on the implementation since I will rely on this collection very much.
-- modified at 21:23 Saturday 4th February, 2006
|
|
|
|

|
Does anybody know of (or are there any plans to build) a generic extension to this cool collection library?
Just thought I'd ask before giving it a try myself (probably a good way to learn a few things about generics I guess).
Nathan
|
|
|
|

|
It looks like there are several good ideas in recent posts. I'll be starting up some .NET stuff again soon, so maybe this would be a good project to familiarize myself with the new tools. Feel free to do it yourself though - the library is really pretty simple, and you'll probably be able to get to it before I will.
|
|
|
|

|
Just a little remark: immutable is not the same as readonly.
An immutable object can not be modified after it has been created. A typical example would be the System.String type.
A readonly view of a mutable object just means that the owner of the view can not modify the underlying object. But it does not guarantee that the underlying object never changes. An example would be what you get out of ArrayList.ReadOnly(). The resulting object can not be used to modify the underyling ArrayList, but if the ArrayList itself changes, then so does the view/wrapper object.
So probably you should rename the class for clarity.
|
|
|
|
|

|
First, congratulations on providing such an excellent and much needed set implementation! Now that this code is also shipped with NHibernate, I am sure many people will be finding it extremely useful.
I have a query about your SortedSet implementation. At present, it uses a SortedList as its backing store? However, I do not believe that, semantically, a SortedList is equivalent to a SortedSet?
Specially, as can be seen at http://www.dotnet247.com/247reference/System/Collections/SortedList/__rotor[^], SortedList uses IComparable and BinarySearch, not GetHashCode() and Equals(), to implement its Add, Contains, etc.
I have a class whose GetHashCode() and Equals() methods key off one property of the object, and whose CompareTo() keys off another. This is because my GetHashCode() and Equals() method use internal, unique identifiers useful to the code whereas my CompareTo() method uses human-readable, non-unique identifiers useful to people.
I believe this is a valid use case: I do not believe the contract of CompareTo() requires it use the same identifier as GetHashCode() and Equals()?
However, SortedSet breaks in this scenario because (I believe) it goes looking for an existing object using CompareTo() rather than by GetHashCode() and Equals(). This means it is possible to put multiple items into a SortedSet whose Equals() methods return true, which breaks the ISet contract (though of course is perfectly valid for a SortedList).
Have I gotten this completely wrong? Is there a better approach?
Regards,
Richard.
-- modified at 17:48 Sunday 4th December, 2005
|
|
|
|

|
CompareTo(), Equals(), and GetHashCode() need to all key off the same value, or at least they need to provide consistent results. If you look at the object one way that is always unique, and another way that can return the same value, you have broken the contract. All three methods must provide consistent behavior - otherwise you can't expect any code that uses your object to behave correctly.
You could get around this by getting rid of CompareTo(). Put the objects into a HashSet. When you need to iterate in order, put the objects into a Dictionary based on the descriptive string. Does that solve your immediate needs?
|
|
|
|

|
A nice solution for this case is to support a comparator in a separate class, implementing the IComparator interface.
System.Collections.SortedList have a constructor that takes an IComparator. It should be easy to add to Iesi.Collections.
Fábio David Batista
blog: http://nerd-o-matic.blogspot.com[^]
company: http://suprifattus.com.br/[^]
|
|
|
|

|
. You made my job simple.
|
|
|
|

|
First off - great code! It opens many new coding approaches.
On to my question: I am putting together a security component that integrates your code into an XML based "expressionizor" that will pass in a session/context item reference. This session/context item is processed out a string. From this string I need the ability to create a new Set using this string variable.
Example:
***************************
string test ="counties";
Set test.String() = new SortedSet;
//need the code to interpret as this
//Set counties = new SortedSet;
Needless to say it throws a casting object error. This is the last issue - all other code works perfectly.
Any ideas????
By the way I add a Values property to return a comma delimited list to easily get a string back for usage. You might think about officially putting that type of property in the class.
Ken
|
|
|
|

|
A string isn't a Set, though an array of Strings is a collection. You can initialize a Set using a collection (or array) of string values.
Since Sets can work with any type of comparable object, it would be rather strange to put methods on Sets for dealing specifically with strings. Also, there are numerous ways to deal with serialization of data: XML, plain text, comma separated, etc.
You may actually want to try some of the .NET serialization stuff as an alternative to rolling your own code. It isn't hard to parse comma separated values, but be sure to deal with the case where your data has a comma in it!
Good luck!
|
|
|
|

|
Thanks for the feedback. I am already applying some of your suggestion deeper in the code.
The issue is the "reference name" of Set. I need to able to create the reference name dynamically.
I am parsing out security xml that has the necessary expression to be applied for a role. A subset example of such is: exp="Set([accesscounties])^Set([datacounty])".
I pull out the necessary equation, parse it, fill the set with the necessary county data (using a collection0, evaluate, and apply necessary security rendering based upon the expression result.
Everything works perfect if I hard code the Set creation (e.g., Set accesscounties = new SortedSet), but all the security rules are created via an interface and the there is no way of knowing the necessary rule(s) at design time.
Hence the issue is being able to create/substitute the "Set" based upon the value in the [] (e.g., Set [name] = new SortedSet).
Any additional help would be great.
Ken
|
|
|
|

|
The compiler must know the name of the variable, and at compile time the code isnt executing, so there is no way to get a dynamic variable name, if your using an interface for generating a set name, then instead of giving a name, just return a sub-set you write yourself which implements the necessary security checks (or whatever is necessary).
You *could* do it dynamically, but then you would have to use CodeDOM (for instance) to actually compile the class on the fly when the code is running, which does seem a bit overkill for your scenario.
|
|
|
|

|
Thanks for the idea. I was thinking of using CodeDOM, but impacts would be too negative since everything sets in one .dll that is being implement for web systems.
The solution was to build a parser to fragment out the string to get the "Set" variable names. Since the var names and values are in a session or cache object, I pull their values directly out using the key name, split() the string to an array and do a .AddAll() to a predefined set objects, and evaluate. At the present, I am only doing a "Minus" operation to evaluate out a True or False on the result, which makes everything fire as needed.
The net result is that it is possible to pass the necessary "set expression" string with variable names via an XML file and evaluate it out to effect rendering security.
In the future I am planning to add a operation determiner (e.g., - , &, |, ...) to provided greater flexibility.
Again, thanks for the input and especially for the base Sets code.
Ken
|
|
|
|

|
Jason
My employer is contracted to build a fines and court penalty management system for the State Government of Tasmania. The client for this system is built as a C# Winform.net application. I'd like to use your library in the client, and having read your previous postings in response to licensing questions, am posting to let you know of the inclusion of your library.
Thanks for the high quality code.
regards
Richard
|
|
|
|

|
Glad you can use it! It is wonderful to know that my code is running down in Tasmania.
|
|
|
|

|
I'd like to use this library commercially as well, but I'm a little nervous since there's no explicit license etc. with the source code, and the message I'm replying to is from "Anonymous", not "JasonSmith". Maybe I'm being paranoid, but I'm not a lawyer so I want to be on the safe side
Could you provide some statement of how this library can be used, redistributed and sold (commercially and otherwise) with the source and/or doc download?
Thanks,
Hugh.
|
|
|
|

|
Sorry for posting anonymously. How's this?
Use the software however you want. It's free to all, the source code is free to all, and if you use it, you own it. Heck, sell it if you can find someone dumb enough to pay for it. I don't care how you use it as long as you don't come looking for me if something goes wrong (unless you want to hire me as a consultant - then we'll talk).
|
|
|
|

|
How does one find an element in a SortedSet so that element gets returned ? There is a Contains function to specify whether or not an element is in a set, but there is no function for returning an element which has been found.
Edward Diener
|
|
|
|

|
Please ignore. I woke up.
Edward Diener
|
|
|
|

|
The Set Collection is written for use in a Windows.NET program, as the RiverDemo is such. However, what must be done to use this in a ASP.NET application also?
|
|
|
|

|
This update includes a number of bug fixes and minor enhancements, plus adds support for a set interface (ISet), and support for Visual Basic (CLS-compliant). Documentation is now delivered as both a CHM and HTML.
|
|
|
|

|
Would you be interrested on making an article "forgotten collection" in the .Net. I think you Set would definitely have a space in that. Other collection such as skiplist, interval tree, priority heaps would be welcome too.
Jonathan de Halleux - www.dotnetwiki.org -
MbUnit - QuickGraph
|
|
|
|

|
Actually, yeah, I would! Do you have anything to submit?
I'm currently working on some requested enhancements, in particular a list-based Set that implements both ISet and IList interfaces, and supports constant-time remove. Thanks to Michael Micco for the idea.
The doubly-linked list I am using will be part of the new library. So it is definitely moving in that direction.
|
|
|
|

|
I have implemented a ternary search tree for fast string search and special "partial match" stuff on string.
We could implement various datastructure written in MSDN articles. Skiplist would be nice and I would love to have a fibonacci heap .
Jonathan de Halleux - www.dotnetwiki.org -
MbUnit - QuickGraph
|
|
|
|
|

|
You might want to make sure you understand the performance ramifications of using linked-list style containers of any significant size under a garbage-collected system before you run out and destroy the performance of any well-intentioned app that references your library.
Linked list style structures place an enormous amount of strain on the garbage collector. This is true
for any GC system (unless of course it were to specifically have corner-cases for dealing with this).
Don't even ask me why Java is so linked-list happy. All I can say to that is that if you look at Java closely, you'll find that Sun made a number of mistakes w/ regards to architecture. (I can't say I blame Sun too much though. To their credit, Java was pretty-much the first modern-day stab at a real-world OO+GC based system.)
Instead of using link structures, consider mitigating the load on the GC by storing your nodes in an
an array-backed pool instead, and make each "link" simply be an index into the array.
deejay
|
|
|
|

|
I just tried dropping this into a compact framework project - It mostly compiled, except for:
- SortedList is not supported.
- Activator.CreateInstance only takes a type argument.
The first one I can kind of ignore since I don't need it (at this time), but I wasn't sure how to handle the 2nd one... (I'm just starting to get my feet wet with C# after 10 years of C++)
Thankx!
Dave
|
|
|
|

|
Sounds like Microsoft has some bugs in the compact framework!
For the first one, rip it out.
For the 2nd one, change the Auto-Clone code in Set:
public virtual object Clone()
{
if(this is ImmutableSet)
return new ImmutableSet(((ImmutableSet)this).BasisSet);
else
{
Set newSet = (Set)Activator.CreateInstance(this.GetType());
newSet.AddAll(this);
return newSet;
}
}
|
|
|
|

|
>Sounds like Microsoft has some bugs in the compact framework! Not really bugs - just limitations! (It is "compact" afterall!) The APIs clearly (well, maybe not clearly) show which APIs are supported. Thankx for the tip on CreateInstance! And I suspect we can probably handle the sorted one - it's just that we have to do the sorting... (From a session at SD'04, it sounded like they stripped out any functionality that could be implemented in terms of what was left - for instance there's no need to supply the CreateInstance you were using since it can be done as you mention above - that makes the API smaller - I believe they said the compact install was under 2M) Dave
|
|
|
|

|
One other thought - Rotor might have the code, all in open source, for SortedList.
|
|
|
|

|
I initially used the ListSet in some code I was writing because I required the order of items in the set to be accessible by the order that I added them. When the number of my items got large, I began to hit the performance wall associated with a ListDictionary (ListSet uses a ListDictionary underneath).
So I went on a quest to find keyed list that performed with a large quantity of objects in it. I had no luck finding one that performed well on addition as well as removal (Intersect uses removal) AND enumerated in the order items were added.
I created my own class, LargeListDictionary, and have just posted that article on CodeProject. I also created a LargeListSet class which inherits Jason's DictionarySet and uses my LargeListDictionary. All, please check them out and feel free to use them.
Here is the current link: http://www.codeproject.com/useritems/LargeListDictionary.asp
Micco.
|
|
|
|

|
This is a nice bit of programming, but I am not quite sure what to do with it. The reason is that Sets, by definition, are unordered.
Let's say you create a Set with {"A", "B", "C", "A"}. Should the resulting Set enumerate as {"A", "B", "C"} or {"B", "C", "A"}? There are also problems with mathematical operators, since a Union or Exclusive-Or should impose two separate orders on the items in the resulting set.
Sorted sets make sense - order is not defined by the mathematical operators. Same for hashed sets. With List-based sets, you can't depend on the order (the underlying implementation could change - you never know). And the way the mathematical operators are implemented now, the order doesn't make much sense anyway.
I am curious as to how you are using this, and why order is important to you. Maybe I can use that information to help improve the library.
|
|
|
|

|
The application where I needed this was an email marketing application. The user starts with some group of their subscribers (in the order they were added), and applies various rules to narrow down the list. The narrowing involves doing an intersection of the current list with the narrowed down list.
Example: All users in order, filter where first name = "bob", filter again where age > 47, etc.
The key is that at the end, the remaining emails are in the order in which they were added initially. This is because when they are sent out, only the first X are processed based on a credit limit. Consistency is needed so the first X are always the same and follow a consistent rule (like FIFO- oldest subscribers first).
So, in this case, we use the sets for the set operation (intersect), but need the final set to be enumerable in order.
Also, the math seems to work as needed for intersect, because the A intersect B operation will remove from A to yield the resulting set. Therefore, the resulting set is in the same order as A. Also with union type operations, you do always get a consistent handling of order. A union B will append new items from B onto A so the resulting set will have A in order with new items from B in B's order. I'm not sure how the other operations would affect the order, but I didn't need to use anything past union and intersect.
Micco.
|
|
|
|

|
I've changed my mind on this. You are the second person who has asked for list-ordered Sets. I'm working on a couple of things towards that end.
First of all, I'm working on a doubly linked list. This is tons faster than ArrayList for Remove operations. It is also a nice alternative to ArrayList in general, when you need to do lots of inserts and removes that are not at the end of the List.
Using a doubly-linked list, along with a Hashtable (thanks for the idea), I'm working on an IDictionary that supports insertion at an index.
Using all of that, I'm putting together a new Set class that also implements the IList interface (most of it anyway). This allows you to insert new values in the middle, at the beginning, or at the end. The asymptotic behaviour is pretty good, as long as you aren't jumping around all over the place randomly with indexed lookups. Keyed lookups (Contains(), Remove()) take constant time.
If anyone wants to try any of this out prior to the availability on CodeProject, let me know and I will email you the code. do if you limit the functionality. And if you do it that way, someone maintaining your code later won't run into ordering bugs caused by my library!
By the way, decent job on the fast-List IDictionary class! That one can stand completely on its own. I would recommend that you go ahead and implement the full IDictionary interface - which will require some architectural changes. But that is a nice class to have around!
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
An implementation of "Sets" for .NET
| Type | Article |
| Licence | |
| First Posted | 13 Nov 2002 |
| Views | 316,348 |
| Bookmarked | 169 times |
|
|