set

CMD For Loop does not hold set /a value

拜拜、爱过 提交于 2019-12-11 02:22:59
问题 Didn't know how to explain this well, so here is the code @echo off set test=0 for /f %%a in (textfile.txt) do ( rem loops five times(5 lines in textfile.txt) set /a test=test+1 rem Adds 1 to Test echo %%a rem Echo's correct line in file echo %test% rem Echo's whatever X was before the loop ) echo %test% rem Displays the correct value of X pause this is just an example of where I am finding the problem, txtfile.txt has 5 lines, so the for loop goes 5 times, each time, test gets +1 to it, and

Set is not working with overridden equals

纵饮孤独 提交于 2019-12-11 02:09:54
问题 I was trying to use set. so i tried this way HashSet set=new HashSet(); Points p1 = new Points(10, 20); Points p2 = new Points(10, 20); System.out.println(set.add(p1)); // output true System.out.println(set.add(p2)); // output false I know my first output will be true and second will be false as Set will not allow duplicate elements. And, i also know Set achieve this by using equals(Object o) method. Which comes from java Object class with following signature. public boolean equals(Object o)

Retrieving the “canonical value” from a Set<T> where T has a custom equals()

你离开我真会死。 提交于 2019-12-11 01:46:43
问题 I have a class Foo which overrides equals() and hashCode() properly. I would like to also would like to use a HashSet<Foo> to keep track of "canonical values" e.g. I have a class that I would like to write like this, so that if I have two separate objects that are equivalent I can coalesce them into references to the same object: class Canonicalizer<T> { final private Set<T> values = new HashSet<T>(); public T findCanonicalValue(T value) { T canonical = this.values.get(value); if (canonical =

How to change object child members in a set

夙愿已清 提交于 2019-12-11 01:39:29
问题 I am using a set to hold objects. I want to make changes to the first object in the set. This is what I tried: set<myClass>::iterator i = classlist.begin(); i->value = 0; This is the error I get: error: read-only variable is not assignable How did the variable become read-only? How can it be changed? 回答1: The things in a set are effectively read-only - you cannot change the value of a member of a set in situ. All you can do is remove it, and add a new member with the required new value. This

Prolog - getting a maximum value of set from a list of facts (using fail predicate)

时间秒杀一切 提交于 2019-12-11 01:27:04
问题 Basically I have a list of facts like this: set(x,2). set(x,7). set(x,10). set(x,4). I need to find the maximum element of this set. Input: maximum(x, MaxElement) Output: MaxElement = 10. Now the idea itself isn't complicated and I saw many examples online myself. The problem is that I need to use the fail predicate. Here was my idea (which doesn't work): maximum(Set, Element1):- set(Set,Element1), set(Set,Element2), Element2 > Element1, fail. maximum(Set, Element) :- set(Set, Element). The

HashSet not removing existing element

 ̄綄美尐妖づ 提交于 2019-12-11 01:18:32
问题 I have a class Output which basically contains a BitSet with overides on hashCode and equals. Then I have a HashSet of Outputs and I do the following operations : Set<Output> outputs = new HashSet<>(); Output o1 = new Output(); o1.flip(3); Output o2 = new Output(); o2.flip(1); o2.flip(3); outputs.add(o1); outputs.add(o2); If I do a print(outputs) I get [Output@5a1, Output@5a3] Now if I do o2.flip(1); I get [Output@5a3, Output@5a3] which of course, is the normal behavior of a Set, since the

Python's equivalent of Java's Set.add()?

梦想的初衷 提交于 2019-12-11 01:06:18
问题 Java's Set.add function will return a boolean value, which is true if the set did not already contain the specified element. Python's Set.add does not have a return value. Seems like in Python if I want to do the same thing, I have to check if it is in the set first and then add it if not. Is there a simpler way to do that (preferably a one-liner)? Ref: https://docs.oracle.com/javase/7/docs/api/java/util/Set.html#add(E) https://docs.python.org/2/library/sets.html#sets.Set 回答1: If you want a

Does Microsoft Access 2003 contain sets or multisets?

大城市里の小女人 提交于 2019-12-11 00:50:38
问题 I'm trying to confirm or deny whether you can define a table column in MS Access 2003 as a set. It seems this is implemented in Office 2007 - you can define a column to have a 'multi-select list' in the query/lookup, but this feature appears to be unique to the new access 2007 file format as far as I can determine. Worded another way, does MS Access 2003 have the equivalent to the SQL statement: CREATE TABLE mytable (foo VARCHAR(10), bar VARCHAR(5) MULTISET); Or is there a clever workaround

Unique object identification of Java Set

旧时模样 提交于 2019-12-11 00:42:57
问题 In Java, a Set cannot contain two unique objects where as a List doesn't have that restriction. What is the mechanism in a Set which identifies unique objects. Most probably it might be the implementation of the equals method or hashCode method or both of the objects which are being added. Does anyone know what's the actually mechanism of identifying unique objects. Is it the equals method, hashcode method or both the methods or something else ? 回答1: It depends on the Set implementation. For

Create a set from a list using {}

久未见 提交于 2019-12-11 00:39:56
问题 Sometimes I have a list and I want to do some set actions with it. What I do is to write things like: >>> mylist = [1,2,3] >>> myset = set(mylist) {1, 2, 3} Today I discovered that from Python 2.7 you can also define a set by directly saying {1,2,3} , and it appears to be an equivalent way to define it. Then, I wondered if I can use this syntax to create a set from a given list. {list} fails because it tries to create a set with just one element, the list. And lists are unhashable. >>> mylist