set

What's the difference between theese two java variable declarations?

in java... public class someclass { private HashSet<Someobject> contents = new HashSet<Someobject>(); private Set<Someobject> contents2 = new HashSet<Someobject>(); } what's the difference? in the end it's both a hashset isn't it? the second one looks just wrong to me but i have seen it frequently used, accepted and working......

doubt in collections

what is the difference among list, queue and set? ...

How does a Python set([]) check if two objects are equal? What methods does an object need to define to customise this?

I need to create a 'container' object or class in Python, which keeps a record of other objects which I also define. One requirement of this container is that if two objects are deemed to be identical, one (either one) is removed. My first thought was to use a set([]) as the containing object, to complete this requirement. However, the...

Set_union/Set_intersect for more than two sets in c++

I know those commands are for two sets. Does there any simple and fast way to do this for more then two sets. I think I can use some kind of loop for this but maybe there are better way. Thank you ...

How is CPython's set() implemented?

I've seen people say that set objects in python have O(1) membership-checking. How are they implemented internally to allow this? What sort of data structure does it use? What other implications does that implementation have? Every answer here was really enlightening, but I can only accept one, so I'll go with the closest answer to my o...

Scala: good way to keep pairs of strings

Hey fellas, What is a neat way to hold pairs of strings which are not necessarily key-values (might have duplicate keys), for a small collection? List[List[String]] works obviously but looks dirty. Cheers Parsa ...

constant-time set operations

Are there constant-time algorithms for binary set intersection and union? I imagine using bitmaps with pointers to elements in the memory and using OR for union and AND for intersection. Does anyone now of a solution? ...

populate c++ maps content in a loop scope

I try to populate the content of a c++ map within a loop scope. #include <set> #include <map> map<int, set<int> > maps; for (int i=0; i<10; i++) { set<int> seti; // content: a set of integers seti.insert(i); seti.insert(...); maps.insert ( pair<int,set<int> >(i,seti) ); } The question is: does maps.insert copy the pa...

STL Set: insert two million ordered numbers in the most efficient manner

For the following mass-insert, because the inputs are ordered, are there any (slight) optimizations? set<int> primes; for ( int i = 2; i <= 2000000; i++ ) { primes.insert(i); } // then follows Sieve of Eratosthenes algorithm New improvement, twice as fast: set<int> primes; for ( int i = 2; i <= 2000000; i++ ) { primes.inser...

Linq2EF: Update Records with result of a CheckBoxList / Set of ID Values

Say I have a CheckBoxList on a page reflecting table data. A user unchecks previously checked items, and checks ones that were not checked. I want to update the database with LINQ2EF so that the records remaining match the newly submitted checked items. In other words, when the page submits, I get a String[] of checked IDs. I then need ...

Java: Set interface and Collection interface differences

I just looked up the Set interface and found that it mostly (or completely) only redeclares functions which are already in the Collection interface. Set itself extends Collection, so doesn't that mean that the Set interface automatically has all the functions from Collection? So why are they redeclared then? For example, Set redeclares ...

Python set and the "in" keyword usage issue

I'm trying to work with a set of django models in an external script. I'm querying the database at a preset interval to get the items that meet the query. When my external script is processing them, it takes a while and I may get the same results in the query if the processing hasn't updated the model yet. I figured I could use a set ...

How to intersect multiple sets?

I have this list: private List<Set<Address>> scanList; So my list contains multiple scans as you can see. After each scan I add new set into the list. After all scans are finished I would like to take only the addresses that occur in every set and put it into: private List<Address> addresses; Does something like this already exist...

Complexity of Set operations

This is what I am doing: String one = "some string" String two = "some string" I want to know all the characters that are in string one and two and they should come in order as they are in string one I wrote a Java program which by using Collections performs set operations on both the collection. What I would like to know that what...

C#: Add child to collection and set child's parent in same call

I'm building a sort of domain layer and I would like to be able to implement the following methods: [Note: ISet is a collection class which doesn't permit duplicates, according to checking using .Equals().] public class Parent { public ISet Children = new HashedSet<Child>; public void AddChild() { ... } public void RemoveChild() { ... ...

Define a set outside of a bean in spring ioc

I understand that a set can be defined as: <bean id="toolbox" class="tools.Toolbox"> <property name="tools"> <set> <ref local="foo" /> <ref local="bar" /> </set> </property> </bean> but I can't find anything in the documentation to allow me to define the set first, for example: <set id=...

NHibernate: use of IEnumerable as collection type results in error

I have a class which uses an ISet as a collection type as below: public class Client { private ISet<Contact> _contacts = new HashedSet<Contact>(); public virtual ISet<Contact> Contacts { get { return _contacts; } } } I don't want the collection itself to be able to be modified externally. However, if I change the propert...

Python: how to add contents of iterable to set?

In Python, what is the "one [...] obvious way" to add all items of an iterable to an extant set? ...

Pointers to objects in a set or in a vector - does it matter?

Hi, just came a across a situation where I needs to store heap-allocated pointers (to a class B) in an STL container. The class that owns the privately held container (class A) also creates the instances of B. Class A will be able to return a const pointers to B instances for clients of A. Now, does it matter if these pointer are stor...

Error CS0051 (Inconsistent accessibility: parameter type 'Job' is less accessible than method 'AddJobs.TotalPay(Job)')

I compiled and ran the source code below successfully by omitting the totalFee field. How do I write totalFee into this program so that it will accurately calculate the total fee for each job (rate * time)? Below, you'll see I tried using a method; which generated the error CS0051 (Inconsistent accessibility: parameter type 'Job' is less...