FAQ Database Discussion Community


Why can't I use pair as key of unordered_set / unordered_map? [duplicate]

c++,dictionary,set,unordered-map,unordered-set
This question already has an answer here: Unordered set of pairs, compilation error 2 answers Both std::set<> and std::map<> can use a std::pair as a key, but why can't std::unordered_set<> and std::unordered_map<>? For example: unordered_set<pair<int,int> > S; S.insert(make_pair(0, 1)); Does not compile....

Equivalent of array join() for Set in Ruby?

ruby,arrays,set
Is there an equivalent of array join() for the Set class in Ruby? or best to just monkey patch my own on the Set class? http://ruby-doc.org/stdlib-2.2.2/libdoc/set/rdoc/Set.html...

Data Structure which can maintain insertion order, filter out duplicate elements and easily remove first element?

java,list,data-structures,set
I need to use a data structure which can maintain the insertion order, do not store any duplicates and I can easily remove first element from it efficiently. public static LinkedHashSet<String> getData(TypeEnum flowType) { LinkedHashSet<String> listOfPaths = new LinkedHashSet<String>(); String prefix = flowType.equals(TypeEnum.PARTIAL) ? TypeEnum.PARTIAL.value() : TypeEnum.UNPARTIAL.value(); listOfPaths.add(prefix + LOCAL_PATH);...

TreeSet not adding all elements?

java,collections,tree,set,treeset
I have been looking into the speeds of different Java collection types and have come across something weird. I am adding 1,000,000 objects from a static array to a different collection type and returning the time required. This part of the code works fine. Under further investigation I noticed that...

Return all sets where all of its numbers are not in any other set

objective-c,algorithm,set
I recently had to solve the following algorithm question, which it confused me. Suppose you have an array of sets that contain integers. Write a function that returns all sets where all of its numbers are not in any other set. EXAMPLE {0,4,9}, {3,4,5}, {6,7,8} RESULT {6,7,8} The code should...

Learning Sets : How do I place the asterisks and ampersands on function arguments and function calls?

c,set,function-pointers,function-call
I am confused as to when to put * and & on function arguments and ampersands on function calls and especially confused on pointers. I would also like to do a dynamic allocation in initialize but is it allowed in sets? What I understand is that my set is only...

unknown behaviour in C# windows form application

c#,class,properties,set
I have one class Product in several properties. The problem is when I set the Count of Product for Customer property the Count of Product for Supermarket would be changed too. I have these classes and properties: class Supermarket { string _name; string _address; string _phoneNumber; List<Product> _products = new...

Template C++: How to access iterator value for both std::map and std::set?

c++,templates,dictionary,stl,set
I have a specific search function. Because it's used on both std::set and std::map, it was duplicated in our code (not using template). I have to maintain those two functions, and I'd like to move them to a single function using a template (and then have only one search preocedure...

Using comparison function for the key type for sets results in runtime error

c++,c++11,set,runtime-error,decltype
I've read this question and it does not help me. My question is: Why am I getting a runtime error when using a comparison function for the key type for set as below? multiset<Phone, decltype(comp)*> phones { Phone(911), Phone(112) }; //^^^^^^^^^^^^^^^ In VC2013 it gives me this for the above...

Different python frozensets with same hash value

python,set,frozenset
My understanding is that hashing two different frozensets (immutable Python sets), which need to contain hashable objects, should lead to two different hashes. Why do I get the output below for two different frozensets? In [11]: a Out[11]: frozenset({(2, -2), (2, -1), (3, -2), (3, -1)}) In [12]: b Out[12]:...

Can Java Set objects be modified in place?

java,set,treeset
I am using a TreeSet but am wondering more specifically for Set in general if it is okay to modify an entry without removing it or if this creates unpredictable behavior. Basically, does the Set/TreeSet reorganize itself internally if it is modified even if the modified entry is not removed...

Removing subsets in array of Sets

arrays,swift,set
Is there an efficient way to remove subsets from an array of sets E.g. array of arrays [[2, 3, 4, 7, 8, 9, 10], [1, 5, 6], [3, 7, 10], [4, 8, 9], [5, 6], [7, 10], [8, 9], [6], [9]] to output an array [[2, 3, 4, 7, 8,...

Printing off the content of Array or Set using for loop

arrays,swift,for-loop,set,println
When trying to print off the content of Set or Array using for loop I don't receive values but number of them. For example: var favouriteSports: Set = ["Snowboarding", "Skateboarding", "Surfing"] for genre in favouriteSports { print("\(genre)") } What I wanted to receive in console is "Snowboarding, Skateboarding, Surfing" but...

n grams scala output set transformation

scala,set,n-gram
def ngrams(n: Int, words: Array[String]) = { // exclude 1-grams (1 to n).map { i => words.sliding(i).toStream } .foldLeft(Stream[Array[String]]()) { (a, b) => a #::: b } } scala> val op2 = ngrams(3, "how are you".split(" ")).foreach { x => println((x.mkString(" ")))} Output as : how are you how are...

get the coordinates from a random position and use them

java,android,button,random,set
My code should work something like this: you see one dark button (clickable, [start_time]) and one grey button (not clickable, [buttongame1]). the buttongame1 predict, where start_time will move next. when you click start_time, start_time moves to x and y of buttongame1. At the same time, buttongame1 set it's position randomly...

Set options for ZADD command in laravel redis

php,laravel,redis,set
I'm trying to set options for ZADD with laravel redis but am failing. The option I need to set is NX, as stated in the documentation: ZADD options (Redis 3.0.2 or greater) ZADD supports a list of options, specified after the name of the key and before the first score...

Merge two boost intrusive sets in C++?

c++,boost,set,intrusive-containers,boost-intrusive
I have two boost intrusive sets which I need to merge it together. I have map_old.m_old_attributes boost intrusive set which I need to merge it to m_map_new_attributes boost intrusive set void DataTest::merge_set(DataMap& map_old) { // merge map_old.m_old_attributes set into m_map_new_attributes } What is the best way to do this? I...

C++ / How does a iterator work for a Set of class object?

c++,pointers,set
I've been teaching myself C++, and found an interesting thing. According to this web page,: The most obvious form of iterator is a pointer. So, I used to think that an iterator object works in almost the same way as a pointer (e.g. int *i); However, now I guess that...

Initialization of list of sets of integers in C++98

c++,list,set
this might seem trivial but I wasn't able to find it on the web so far, so I want to initialize a list of sets of integers or a set of sets of integers, like this: list< set<int> > lsi = {{}}; or maybe like this: set< set<int> > ssi...

Using a text file as a set of values swift [duplicate]

ios,swift,set,text-files
This question is an exact duplicate of: Getting a set of values from resource file swift [closed] I'm working on a project that selects one or more words contains entered(user) keywords.That's why I'm using a set. But the set is turkish dictionary. That is to say, it contains 68k...

Opposite of set.intersection in python?

python,set
In Python you can use a.intersection(b) to find the items common to both sets. Is there a way to do the disjoint opposite version of this? Items that are not common to both a and b; the unique items in a unioned with the unique items in b?...

Comparing arrays, sets & their elements in SWIFT

ios,arrays,swift,multidimensional-array,set
I'm fairly new to coding in and I usually find answers already on here. However on this occasion I've been trying to find a method in swift that will allow me to identify pairs of numbers, in another array of unpaired numbers within another array for example in the image...

Creating an Attribute class that allows adjusting a base value?

python,python-3.x,get,attributes,set
I want to create an Attribute class so I can do stuff like: class Creature: def __init__(self, health=100, armor=0): self.health = Attribute(health) self.armor = Attribute(armor) Now when I do c1 = Creature() c1.health += 10 It actually doesn't change the real value, but it keeps health's base value at 100,...

Python: Split list in to sets

python,set,iterable,enumerate
I'm trying to split a list in to enumerated sets and I have a implementation that seems to do what I want but it doesn't feel very "pythonic" is there a better way? The below example splits the item in to sets of maximum size 3 and returns each item...

Get unique values in List of Lists in python

python,list,set,unique
I want to create a list (or set) of all unique values appearing in a list of lists in python. I have something like this: aList=[['a','b'], ['a', 'b','c'], ['a']] and i would like the following: unique_values=['a','b','c'] I know that for a list of strings you can just use set(aList), but...

Bitwise and of subsets of an array

arrays,set,bit-manipulation,bitwise-operators
Can anyone give a hint how to approach this problem? Given an array A. Is there any subset of array A in which if we do AND of all elements of that subset then output should be in power of two. I've thought of generating a power-set and solving but...

Should I check if an item is already in a set before adding it?

python,set
If foo is a builtin set that I know contains "bar", which of these is faster? Which is more Pythonic? foo.add("bar") or if foo not in bar: foo.add("bar") ...

Java List get last duplicate Object

java,list,set,hashset
I have a list of Objects which is filled dynamically and I want to keep only the last duplicated Object. I tried the HashSet to remove duplicates but it's not doing big thing in my case.Can anyone help with this ? My User Object shown below: public class User {...

Swift pick random item of Set [duplicate]

swift,set
This question is an exact duplicate of: How to get random element from a set in Swift? 2 answers I know, a Set is na unordered datastructure, however I wondered if it is possible to pick a random object of the Set's entries. Is this possible in Swift and...

python - split a list in pairs and unique elements

python,set,partition
I'm having a hard time trying to achieve the following: I have a list (say, [a,b,c,d]) and I need to partition it into pairs and unique elements in every possible way (order is not important), i.e.: [a,b,c,d], [(a,b), c,d], [(a,b), (c,d)], [a, (b,c), d], [(a,d), (b, c)]... and so on....

setof in model data and script files for NEOS server

set,ampl,neos-server
In submitting my AMPL formulation to the NEOS server, why does the below codeline using the `setof' operator work fine in a model file but not in a data file? set X := setof {indices in Y} subsetofindices The NEOS server requires the code be separated into a .mod ,...

Set S of n numbers - have a subset with the probability of each element of S occuring in it equal

algorithm,set
I have this problem You are given a set S of n numbers. You must pick a subset S′ of k numbers from S such that the probability of each element of S occurring in S′ is equal (i.e., each is selected with probability k/n). You may make only one...

Create sets in perl

perl,set,hashes
I'm trying to look for sets in three input conditions (See diagram attached). For example: C1: I want to create a set in perl with some values C2: how to create set these values C3: a set in perl with values like these Would yield a set diagram something like...

Reduce list of lists if entries match

python,list,set
I have a list in python which looks like [['boy','121','is a male child'],['boy','121','is male'],['boy','121','is a child'],['girl','122','is a female child'],['girl','122','is a child']] I want to reduce the list based on the first 2 entries in each list, to get [['boy','121',is a male child, is male, is a child'],['girl','122','is a female child','is...

How to check if a value is present in any of given sets

python,set
Say I have different sets (they have to be different, I cannot join them as per the kind of data I am working with): r = set([1,2,3]) s = set([4,5,6]) t = set([7,8,9]) What is the best way to check if a given variable is present in either of them?...

retrieve all the smallest strings from a set in python

python,string,list,set,min
I have a set which looks like set(['A', 'BF', 'B', 'BA', 'ABF', 'AF', 'F', 'BFA', 'AFB', 'BAF', 'FA', 'FB', 'AB', 'FAB', 'FBA']) and I'm trying to get all Strings which has the smallest length into a list I tried using print min((element for element in getParts(working_scheme,k)), key=len) which just prints...

Removing duplicates from arraylist using set [duplicate]

java,arraylist,set
This question already has an answer here: Common elements in two lists 4 answers Have 2 sets with duplicates set1 ={1,2,3,4,5} set2 = {1,3,6,7} and the result should be set3 ={2,4,5,6,7} Please let me reiterate that I want to use Set interface and the result set should be ordered...

Generate all combinations of strings and their substrings in a set — python

python,string,set,combinations
I want to get all combinations of of strings from a set of strings. For Example: permut = set() permut.add("D") permut.add("C") def getAllKombos(stuff): returnvalue = set() for L in range(0, len(stuff) + 1): for subset in itertools.combinations(stuff, L): for i in subset: x = x + (str(i)) returnvalue.add(x) x =...

How to group sets by similarity in contained elements

python,set,similarity
I am using Python 2.7. I have routes which are composed of arrays of nodes that connect to each other. The nodes are identified by a string key, but for ease I will use numbers: sample_route = [1,2,3,4,7] #obviously over-simplified; real things would be about 20-40 elements long I will...

how find all groups of subsets of set A? Set partitions in Python

python,algorithm,python-3.x,set,subset
I want to find an algorithm that given a set A to find all groups of subsets that satisfy the following condition: x ∪ y ∪ .... z = A, where x, y, ... z ∈ Group and ∀ x,y ∈ Group: x ⊆ A, y ⊆ A, x ∩...

Multidimensional List get Position of a String Python

python,string,list,indexing,set
I got following List relational_scheme = [["F",["DC"]],["A",["EBD"]],["DC" , ["BAF"]],["E",["DB"]]] Now i want to get the second List as a Set like def returnSetOfList(relational_scheme,"F") So that this output generates set(["DC"]) How can i make this? an easy Index don't work. Thanks in advance. UPDATE got it, was just blind Solution: def...

Scala Set different operations

scala,set,operation
So here is my code snippet: val check = collection.mutable.Set[String]() if (check.isEmpty) { println("There is no transfer data available yet, please use the 'load' command to initialize the application!") } val userSelection = scala.io.StdIn.readLine("Enter your command or type 'help' for more information:") val loadCommand = """^(?:load)\s+(.*)$""".r userSelection match { case...

Android List and Array set

android,arrays,list,set
I'm trying to save this info on a Service that is triggered by receiving a call but it's crashing after I use the .set SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss dd-MM-yyyy", Locale.getDefault()); Calendar calendar = Calendar.getInstance(); String currentDateTimeString = df.format(calendar.getTime()); List<String> lastCall = new ArrayList<String>(); lastCall.set(0, currentDateTimeString); lastCall.add("12:22:12 12-03-2014"); lastCall.add("22:06:34 14-07-2013");...

how to convert list of lists to a set in python so I can compare to other sets?

python,list,set
I have a list users_with_invites_ids_list, formed by loop where I append values to the list, in python that looks like this: ...[ObjectId('55119e14bf2e4e010d8b48f2')], [ObjectId('54624128bf2e4e5e558b5a52')], [ObjectId('53a6e7bc763f4aa0308b4569')], [ObjectId('55241823bf2e4e59508b494c')]] when I try: users_with_invites_ids_set = set(users_with_invites_ids_list) I get: TypeError: unhashable type: 'list' How do I convert this list of lists to a set? EDIT based...

C++ why does empty set::emplace() inserts an element into a set of pointers?

c++,c++11,set,move-semantics
Consider the following code: struct A{}; int main() { std::set<A*> aset; aset.emplace(); std::cout << aset.size() << std::endl; //prints "1" return 0; } DEMO Why does the empty emplace() adds an element to the set of pointers?...

How do nested variable types change time complexity?

python,list,dictionary,set,time-complexity
I'm creating a list with nested types like this: nested = [{}, set([]), []] Assume each item in 'nested' has many items in it. For each type of item in 'nested', what operations from Python's Wiki change complexity because the items are nested? For things like add, remove, pop, etc....

Variable indexes outside of defined range in AMPL

variables,indexing,set,linear-programming,ampl
Not too familiar with AMPL, but running into some issues with indexes... Basically, I have some variables defined as such: var array{i in set}; And I need to do some amount of checking the elements around a given i in some of the constraints: subject to Constraint{i in set}: array[i]...

How to use set(data structure) in mongodb console?

javascript,set
As I understand, the mongodb console has an integrated javascript interpreter so my question is why this code does not work if its a valid javascript: //db = connect("localhost:27017/tecnicas") function getRandomInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } diaFavorito = ["lunes", "martes", "miercoles", "sabado"]...

Swift 1.2 Set to Array

arrays,swift,set
An NSSet can be converted to Array using set.allObject() but there is not such method in the new Swift 1.2's Set. It can still be done by converting Swift Set to NSSet and use the allObject() method but that is not optimal. I have been searching around for solution but...

Empty set in LINQ in C#

c#,linq,set
public static string ToHtml(List<int> tags) { var found = Values.Where(v => tags.Contains(v.Key)); if (found.Any()) return found.Select(v => v.Value.ToHtml()).Aggregate((v1, v2) => v1 + v2) + " "; else return String.Empty; } The code first finds a set of pairs from the dictionary where a condition is met. Then if the...

Guava Sets.intersection bad performance

java,performance,collections,set,guava
I've encountered a strange problem in production today. Though I love Guava, I ran into a use case where Guava's Sets.intersection() was performing pretty badly. I've written a sample code: Set<Long> cache = new HashSet<>(); for (long i = 0; i < 1000000; i++) { cache.add(i); } Set<Long> keys =...

How to store 2D geometry vectors in std::set

c++,c++11,vector,set
I've recently attended programming competition. One task was about geometry. Solution, that I invented was to use container of 2D vectors, where each vector is unique. The fastest container, which throws out copies is std::unordered_set. But I forgot how to make custom hash, so I used std::set: struct Vector {...

set values from jquery array of objects php?

php,jquery,arrays,set,value
I am getting particular list of product items through ajax, by passing their unique id to server. Now each product has its own set of properties which I have to display on page with product image. When I set the values through jquery, only last value in the array got...

Getting unique tuples out of a python set

python,python-2.7,set,tuples,unique
I currently have a set like the following: {(a,b), (b,a), (c,b), (b,c)} What I Would like to have is: {(a,b), (c,b)} As you may notice the duplicate values have been removed completely so that two tuples never have the same elements inside regardless of order. How can I tell the...

MySQL Set without predefined values

mysql,sql,set
I want to have a MySQL column as a SET for multiple ID's, but I don't want to predefine all possible values. What I'm looking for is a MySQL datatype, which supports set-functionalities like IN in a MySQL query. It's only used for numeric entries....

Python Function with Lists and Sets

python,list,function,set
So I'm trying to figure out this problem and I can't figure out why it isn't working. The premise is that you're given an input list and you have to find the second-lowest value. The list can have any number of integers and can repeat values; you can't change the...

Longest substring with only 2 distinct chars in C++

c++,string,stl,set
I am trying to find the longest substring with at most 2 distinct characters. It is a brute force program which just uses all possible substrings and checks if they have 2 or more distinct chars. I use a set to keep track of the distinct chars. #include <iostream> #include...

Keep (minim) object in a collection by two attribute keys in java

java,collections,set,comparator,treeset
For example I have a list that contains 3 objects: List<Student> studentList= new ArrayList<Student>(); list.add(new Student("name1", 5); list.add(new Student("name3", 6); list.add(new Student("name1", 7); class Student{ String name; Integer grade;} My filtering logic: if name is equal then i need to filter out the objects that have maximum grade - so...

How to generate all partitions of a set

algorithm,set,combinatorics,backtracking
For a set of the form A = {1, 2, 3, ..., n}. It is called partition of the set A, a set of k<=n elements which respect the following theorems: a) the union of all the partitions of A is A b) the intersection of 2 partitions of A...

Set-theoretic definition of natural numbers (recursion)

c++,recursion,numbers,set
I'm taking a discrete mathematics course, and I'm required to develop a c++ program which receives a string as an input and returns which natural number (if any) it represents. Natural numbers are defined as follows: 0 = {}, 1 = {{}}, 2 = { {} {{}} }, 3 =...

Get & Set MySQL Select

c#,mysql,get,set
What am i missing here, it seems the main form is not calling the method from tsDBCon class and not connecting to the database, i need help, i'm new to get:set properties, am i doing it wrong or what? thanks. public class tsDBCon { private string _user; private string _pass;...

How to access an attribute of an arbitrary element of a set

python,set
I have a non-empty set S and every s in S has an attribute s.x which I know is independent of the choice of s. I'd like to extract this common value a=s.x from S. There is surely something better than s=S.pop() a=s.x S.add(s) -- maybe that code is fast...

Find the equal sets of strings and their count (distinct lists)

c#,linq,count,set,distinct
I'm trying to find the distinct sets and their count. Say you have the following model. public class AModel { public IList<string> Tags { get; set; } } And you have a list of the above model, let's say 50.000 instances of AModel with 1...N Tags. I need to find...

LinkedHashSet and subList, getting n of collection

java,math,set,linkedhashset
I am trying to do a homework in math which is find a subset of collection {1,2,..,n} where n is a number given in the code, I cannot get it done with the sublist so I need to get your help with a math programming. For example for n =...

How to reduce usage of List in the code?

java,list,collections,enums,set
I have an EnumSet like this so to shuffle the elements, I need to convert it to List. EnumSet<Fruit> otherFruits = EnumSet.complementOf(CURRENT_FRUIT); Below is my code where I am doing shuffling and adding it original result list: private static List<Fruits> getFruits() { EnumSet<Fruits> local = EnumSet.of(CURRENT_FRUIT); // first element in...

What is the Pythonic way to iterate over set intersection and exclusions?

python,dictionary,set,iteration,set-intersection
set_of_A_key and set_of_B_keyare two set of keys of dictionary dict_A and dict_B. I want operate over the dictionary values for the keys in the following three sets: (set_of_A_key & set_of_B_key), (set_of_A_key - set_of_B_key) and (set_of_B_key - set_of_A_key) What is the pythonic way to do this? This one is elegant with...

How to access class data in a set of pointers to that class

c++,set
I have a set of pointers: set<StudentInterface*, Comparator> studentSet; These pointers point to Student classes which inherit from StudentInterface and contain an int value ID. I want to test if a certain class has a particular value for ID. My current idea for doing so is as follows: if(studentSet.find(????->getID()) !=...

Datepicker set today's day as a default

javascript,jquery,datepicker,set,default
So I have a datepicker and when I select a day, the day of the week is inserted into another input. $( "#datepicker" ).datepicker({ dateFormat: "dd-mm-yy", onSelect: function(){ var seldate = $(this).datepicker('getDate'); var day = seldate.getUTCDay(); var weekday=new Array(); weekday[0]="Maandag"; weekday[1]="Dinsdag"; weekday[2]="Woensdag"; weekday[3]="Donderdag"; weekday[4]="Vrijdag"; weekday[5]="Zaterdag"; weekday[6]="Zondag"; var dayOfWeek = weekday[day];...

How to remove a customized object using stl remove from container set?

c++,stl,set,remove-if
Following is the class and container class student { std::string name; int id; } set<Student*, compare> s; // sorted by id that i have done correctly class compare { public: bool operator()( Student* s1, Student* s2) { return s1->id < s2->id; } }; How to remove a object from set...

Looking for elements in a set

python,set
I'm a little confused on which data structure to use to compare if an element matches another element in a set. Lets say user_input asks the user to type in their name. if their name matches up they are granted access but this doesn't work. access = set(['John', 'Jane', 'Jack',...

Restore the original order based on many incomplete ordered sets

algorithm,sorting,set
Let's say my original data is 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 It got corrupted and all I have is a few incomplete sets where the order is valid but not all elements are present. 1, 4, 6, 7, 8, 11, 12 1, 2,...

Handling caching of very large set

java,file,memory,set
I have a Set of BigInteger that I want to cache. This Set can go up to ~100K size. The application i'm using is quite light : it does not have a lot of memory (heap about 256mb) and does not use a database (the team is considering it for...

How to add prefix to all the elements of List efficiently?

java,list,collections,set
I have a List in which I need to add a prefix in all the elements of my list. Below is the way I am doing it by iterating the list and then adding it. Is there any other better way to do it? Any one-two liner that can do...

Scala set element uniqueness: What to implement for comparison of user defined classes?

scala,set,compare,unique
I am trying to find this information in the Scala documentation but it looks like it is not there. In the case of Java this was dependent of the Set implementation that was used, AFAIK. In some cases the method to implement was equals, in the case of a HashSet...

Python Convert set to list, keep getting TypeError: 'list' object is not callable

python,list,set
I am trying to write a program that adds items to a list based on a random number. Part of the program is potentially rolling additional items, but all duplicate items should be rerolled. My issue is that when I try to do this using the methods I was able...

Solution to Finding Start of Loop in a Circular Singly Linked List

set,hashset,singly-linked-list
The common solution that I find to this problem is to use 2 pointers that advanced through the linked list at different intervals (i.e. have p1 traverse one node at a time and p2 traverse two nodes at a time) until p1 and p2 are equals. Example: Finding loop in...

Java String Parser to find string, save it and print it

java,email,parsing,set
I wrote this little part down here to find tags in email subjects, extract them and save them to my Set. I.e. if email subject is "Hello there #bro #senpai" it should find and extract both 'bro' and 'senpai' and put it into m_aTags (which is just custom type Set...

how to set and update a database filed to random numbers

php,random,numbers,set
hello i have a table where data is stored, this table consist of a field called tnx_ref, i am trying to automatically update this field with random numbers anytime i update my table this is what i tried, $tnx_ref = $_SESSION['genref']; $sql = "UPDATE transactions ". "SET tnx_ref = '62323232'"....

First and last names not reading in together into set

c++,string,set,fstream
I am having trouble with reading in a text file full of names (some are repeated) and inputting the first and last names together on 1 line. The program works and deletes repeated names but outputs them in alphabetical order with first and last names being treated as 2 different...

Reversing logic of a product-country mapping

python,dictionary,set
I have a dictionary that maps the territory_code to what productIds are available: items = {'US': set(123, 948, 200), 'AG': set(132, 123), 'AZ': set(123)} I would like to reverse the mapping so it gives me the items and maps those to the territory. It should give me: {123: set('US', 'AZ',...

Making and comparing Sets in Coq

set,equality,coq
I'm having trouble understanding whether it is possible to prove that two sets (in this case regular languages) are identical and thus interchangeable. From what I understand, sets can be equivalent even if they are not constructively equal. Regular languages are sets of strings, but I don't see how to...

Joining (union) of Sets inside a Set in Java

iterator,set,java-7,java-api,set-union
I have a map where the values are sets of integers. What i'd want to do is to get in the best way possible (using only the Java API would be great) the union of all the sets of Integers. Map<Long, Set<Integer>> map; What I thought so far is to...

The union of several vectors

matlab,set
I have three vectors, v1, v2, and v3, each of which has 500 values. The three vectors may or may not have the same values. I want to know how to get the union set of the three vectors. If they have same values, the value can only be dislayed...

Javascript: pushing certain info to Array and getting info out of array

javascript,arrays,if-statement,get,set
I have a question about the following problem: I made a board for a game made out of pieces. Each piece has its own x and y coordinates, but also a boolean wether it's a road or not and wether it has a turret on or not. So this is...

Convert several JComboBoxes, JButtons to a Set in an efficient way

java,swing,collections,set,jcombobox
My program uses several JComboBoxes and JButtons to allow the users how and which data is shown. Until today I did this with many of these: if (e.getSource() == someMenü_or_Button){ if(someMenü_or_Button.getSelectedItem()=="showstuff")display.oneOfManySetter(0); } Now I thought that I could collect all the options in a Set<String> Attributes = new HashSet<String>(); But...

Order-independant Hash Algorithm

java,algorithm,hash,set
I am currently working on a collection library for my custom programming language. I already have several data types (Collection, List, Map, Set) and implementations for them (mutable and immutable), but what I was missing so far was hashCode and equals. While these are no problem for Lists as they...

Unexpected behaviour in Python OrderedSet.issuperset()

python,set,set-theory
I have two OrderedSets and I'm trying to check whether one in a subset of the other - both the elements and their order is important. However, the orderedset package is giving me strange results. >>> import orderedset >>> a = orderedset.OrderedSet([433, 316, 259]) >>> b = orderedset.OrderedSet([433, 316, 69])...

Python Sets, Keys, and Dictionaries

python,function,dictionary,set,key
What I'm trying to do is ask the user for a name and then find out in how many clubs a person is, using sets and keys. I'm still new to dictionaries and sets, so I'm a bit confused with how to go about this. So far, I have this...

Observing changes to ES6 Maps and Sets

dictionary,set,ecmascript-6
Is there any way to observe additions to and removals from ES6 Maps and Sets? Object.observe doesn't work because it is only applies to direct properties of the observed object. Hypothetically the size property could be observed, but no indication would be provided of exactly what has changed. Another idea...

Safest way to efficiently modify set element that is used as a key

c++,performance,set,undefined-behavior
I have std::set<std::set<T>> whose inner sets I need to modify frequently. How can I do this efficiently? The only ways I can come up with either seem to cause undefined behavior or cause the entire inner set to be copied, both of which seem like bad ideas....

VBA excel: For Each..Next doesn't go through the selected Range?

excel,vba,excel-vba,foreach,set
I am trying to run my code: Sub Test() Dim vuosi As Integer Dim kk As Integer Dim cF As Range Dim c As String Dim cell As Range vuosi = Application.InputBox(Prompt:="Syötä vuosi, jota haluat tarkastella.") kk = Application.InputBox(Prompt:="Syötä kuukausi(1-12), jota haluat tarkastella.") If vuosi = 2014 Then c =...

Why are nested dictionaries OK but nested sets forbidden?

python,dictionary,set,hashtable
Why are nested dictionaries allowed in Python, while nested sets are disallowed? One can nest dictionaries and change the sub-dictionaries on the fly, as the following demonstrates: In [1]: dict1 = {'x':{'a':1, 'b':2}, 'y':{'c':3}} In [2]: dict2 = {'x':{'a':1, 'b':2}, 'y':{'c':3}} In [3]: dict1 == dict2 Out[3]: True In [4]:...

Arrangements of sets of k positions in a n-competitors race

java,algorithm,function,math,set
this is a copy of my post on mathexchange.com. Let E(n) be the set of all possible ending arrangements of a race of n competitors. Obviously, because it's a race, each one of the n competitors wants to win. Hence, the order of the arrangements does matter. Let us also...

How can I get and remove the first element from a data structure?

java,list,set
I need to use a data structure which can - maintain the insertion order. do not store any duplicates. And I can easily get and remove first element from it efficiently. Below is my code which uses LinkedList but it doesn't filter out any duplicates. And it has removeFirst() method...

Adding a sentence word by word into a set using Recursion

java,recursion,set
I am trying to add each word of a sentence into a set using recursion in java. Punctuation does not matter. My problem is that only the first word of the sentence is being printed after I print the list. For example the sentence "One Two Three Four" would come...

Open VF page when clicked on lookup icon with conditional records

set,salesforce,lookup,apex
i am trying to get this running with some modifications. http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/ I have to get those accounts of which my contact is having contact role and account which it belongs to. I have written soql query and having different accounts from two ojbects. I saved the list as set to...

Ordered set in Redis based on more than one criteria

redis,order,set,unix-timestamp
I am trying to create a redis ordered set. The catch is the ordering need to be done based on two criteria, timestamp and score. But in redis, I can only provide one soring criteria: ZADD {key} {timestamp} {value} How to add score in this ordering as well plz? Update:...

Set from a List of Sets

python,set
I am working in Python. I have a large list L = [X_{1}, X_{2}, ....,X_{n}] where each X_{i} is a set. It is possible that for some distinct indices i, j we have X_{i} = X_{j}. I want to create a list (or a set) L_{1} = [Y_{1}, Y_{2}, ......

Java How create a set of object with two classes?

java,object,set
I have a logical problem to understand, how create a private set of inhabitant object. Here my two classes: package main; import java.util.Set; /** * @author * @version 0.1 * */ public class City { private String name; /** *HERE is my Problem*/ private Set<Inhabitants> Inhabitants { } /** *...

Element is present but `Set.contains(element)` returns false

java,hash,set,contains,hashset
How can an element not be contained in the original set but in its unmodified copy? The original set does not contain the element while its copy does. See image. The following method returns true, although it should always return false. The implementation of c and clusters is in both...