Wiki

Changes between Initial Version and Version 1 of Set

Show
Ignore:
Timestamp:
08/05/12 15:19:11 (12 years ago)
Author:
jaegs
Comment:

Creating page

Legend:

Unmodified
Added
Removed
Modified
  • Set

    v1 v1  
     1{{{ 
     2#!cobra 
     3 
     4 
     5interface ISet 
     6 
     7    def addRange(items as IEnumerable<of T>) 
     8  
     9    def clone 
     10  
     11    def difference(s as ISet<of T>) 
     12  
     13    def intersection(s as ISet<of T>) 
     14  
     15    def isSubsetOf(s as ISet<of T>) 
     16  
     17    def isSupersetOf(s as ISet<of T>) 
     18  
     19    def symmetricDifference(s as ISet<of T>) 
     20  
     21    def toList 
     22  
     23    def union(s as ISet<of T>) 
     24  
     25class Set 
     26""" 
     27A Set holds a hashed, unordered collections of items. 
     28Membership testing and set operations (intersection, union, etc.) are faster than with lists, but order is not preserved. 
     29Set implements ICollection, so it has the usual collection operations such as `add`, `count` and `contains`. 
     30It also has set specific operations including `union`, `intersection` and `isSubsetOf`. 
     31 
     32As with other collections, to create a copy of a set, create a new one passing the original to the initializer: 
     33s = Set<of int>(s) 
     34 
     35TODO: 
     36[-] List style items 
     37[ ] Can the methods use .getType instead of hardcoding Set? Then subclasses would get created for example .intersection 
     38[ ] could use an indexer: s[key].  Does it return bool or T? like NSSet? 
     39[ ] Test without args: s = Set(s)  (test in C# too) 
     40[ ] yielded versions of Set operators? 
     41[ ] unit test CobraCore.toTechString() results 
     42[ ] ReadOnlySet? 
     43[ ] Move some method implementations up to ISet extension 
     44""" 
     45 
     46 
     47    shared 
     48     
     49        const defaultCapacity = 8 (as int) 
     50  
     51     
     52     
     53    var _data as Dictionary<of T, T> 
     54  
     55     
     56    cue init 
     57  
     58    cue init(comparer as IEqualityComparer<of T>) 
     59  
     60    cue init(items as IEnumerable<of T>) 
     61  
     62    cue init(capacity as int) 
     63  
     64    cue init(items as IEnumerable<of T>?, comparer as IEqualityComparer<of T>?) 
     65  
     66    cue init(capacity as int, items as IEnumerable<of T>?, comparer as IEqualityComparer<of T>?) 
     67  
     68     
     69    get count as int 
     70  
     71    get countOfISet as int 
     72  
     73    get isReadOnly as bool 
     74  
     75     
     76    def add(item as T) 
     77  
     78    def addRange(items as ISet<of T>) 
     79  
     80    def addRange(items as IEnumerable<of T>) 
     81  
     82    def clear 
     83  
     84    def clone 
     85        """ 
     86        Returns a new set with the contents of this set. 
     87        Does not clone the contents themselves. 
     88        This is sometimes known as a "shallow copy". 
     89        """ 
     90         
     91    def contains(item as Object) 
     92  
     93    def contains(item as T) 
     94  
     95    def copyTo(array as T[], arrayIndex as int) 
     96  
     97    def difference(s as ISet<of T>) 
     98        """ 
     99        Returns a new set with elements in this set that are not in `s`. 
     100        """ 
     101         
     102    def equals(other as Object?) 
     103  
     104    def getEnumerator 
     105  
     106    def getEnumerator 
     107  
     108    def getHashCode 
     109  
     110    def intersection(s as ISet<of T>) 
     111        """ 
     112        Returns a new set containing only the elements that are in this set and `s`. (AND) 
     113        """ 
     114         
     115    def isSubsetOf(s as ISet<of T>) 
     116  
     117    def isSupersetOf(s as ISet<of T>) 
     118  
     119    def remove(item as T) 
     120  
     121    def symmetricDifference(s as ISet<of T>) 
     122        """ 
     123        Returns a new set with elements in either s or t but not both. (XOR) 
     124        """ 
     125         
     126    def toList 
     127  
     128    def union(s as ISet<of T>) 
     129        """ 
     130        Returns a new set containing the elements of that are in this set or `s`. (OR) 
     131        """ 
     132         
     133interface ISet 
     134""" 
     135This interface is to facilitate Set<of>.equals when the generic types are different (which 
     136does not necessarily restrict the two sets from having the same contents). 
     137 
     138Use ISet<of T> instead. 
     139""" 
     140 
     141 
     142    get countOfISet as int 
     143  
     144     
     145    def contains(item as Object) 
     146 
     147}}} 
     148Browse source - [source:cobra/trunk/Source/Cobra.Core/Set.cobra Set.cobra]