set

Delphi 2009 - Bug? Adding supposedly invalid values to a set

前提是你 提交于 2019-12-22 05:25:19
问题 First of all, I'm not a very experienced programmer. I'm using Delphi 2009 and have been working with sets, which seem to behave very strangely and even inconsistently to me. I guess it might be me, but the following looks like there's clearly something wrong: unit test; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; procedure Button1Click(Sender: TObject); private test: set of 1..2;

HashSet contains() method

让人想犯罪 __ 提交于 2019-12-22 05:18:37
问题 I executed below code and found the output was false . import java.util.Set; import java.util.HashSet; public class Name { private String first, last; public Name(String first, String last) { this.first = first; this.last = last; } public boolean equals(Object o) { if (!(o instanceof Name)) return false; Name n = (Name) o; return n.first.equals(first) && n.last.equals(last); } public static void main(String[] args) { Set<Name> s = new HashSet<Name>(); s.add(new Name("Donald", "Duck")); System

Find the maximally intersecting subset of ranges

删除回忆录丶 提交于 2019-12-22 05:18:07
问题 If you have a set of ranges, such as the following simple example... [ [12, 25], #1 [14, 27], #2 [15, 22], #3 [17, 21], #4 [20, 65], #5 [62, 70], #6 [64, 80] #7 ] ... how do you compute the maximally intersecting subset (not sure quite how to phrase it, but I mean "the subset of ranges which intersects and has the highest cardinality") and determine the degree of intersection (cardinality of ranges in that subset)? Logically I can work it out, and might be able to translate that to a naive

Check if a collection of sets is pairwise disjoint

霸气de小男生 提交于 2019-12-22 05:16:19
问题 What is the most efficient way to determine whether a collection of sets is pairwise disjoint? -- i.e. verifying that the intersection between all pairs of sets is empty. How efficiently can this be done? 回答1: Expected linear time O(total number of elements): def all_disjoint(sets): union = set() for s in sets: for x in s: if x in union: return False union.add(x) return True This is optimal under the assumption that your input is a collection of sets represented as some kind of unordered data

locate sub-vector<string> in another vector<string>

对着背影说爱祢 提交于 2019-12-22 05:12:15
问题 I have a vector<string> v1 = {"A","B","C"} . I want to check if v1 is included in vector<string> v2 = {"X","Y","A","B","C","D"} . Can I find if a set is a subset of the other by using STL ? The vectors should not be sorted If the subset is found just once the algorithm stops " if(counter == v1.size()){break;} ". Do you think that I should allow it to continue the search in case the subset is repeated twice? #include <vector> #include <iostream> #include <algorithm> using namespace std; float

Memory Leaks - STL sets

一世执手 提交于 2019-12-22 04:39:09
问题 I am trying to plug up all my memory leaks (which is massive). I am new to STL. I have a class library where I have 3 sets. I am also creating a lot of memory with new in the library class for adding info to the sets... Do I need to deallocate the sets? If so, how? Here is the library.h #pragma once #include <ostream> #include <map> #include <set> #include <string> #include "Item.h" using namespace std; typedef set<Item*> ItemSet; typedef map<string,Item*> ItemMap; typedef map<string,ItemSet*

How can I convert MultiMap<Integer, Foo> to Map<Integer, Set<Foo>> using Guava?

牧云@^-^@ 提交于 2019-12-22 03:46:52
问题 I'm using MultiMap from Google Guava 12 like this: Multimap<Integer, OccupancyType> pkgPOP = HashMultimap.create(); after inserting values into this multimap, I need to return: Map<Integer, Set<OccupancyType>> However, when I do: return pkgPOP.asMap(); It returns me Map<Integer, Collection<OccupancyType>> How can I return Map<Integer, Set<OccupancyType>> instead ? 回答1: Look at this issue and comment #2 by Kevin Bourrillion, head Guava dev: You can double-cast the Map<K, Collection<V>> first

Does Set in Ruby always preserve insertion order?

谁说我不能喝 提交于 2019-12-22 03:46:22
问题 i.e., is Ruby's Set equivalent to Java's LinkedHashSet? 回答1: In Ruby 1.9: yes . In Ruby 1.8: probably not . Set uses a Hash internally; and since hashes are insertion-ordered in 1.9, you're good to go! As mu is too short points out, this is an implementation detail and could change in the future (though unlikely). Thankfully, the current implementation of Set is pure ruby, and could be adapted into an OrderedSet in the future if you like 来源: https://stackoverflow.com/questions/10361250/does

How can I convert MultiMap<Integer, Foo> to Map<Integer, Set<Foo>> using Guava?

喜夏-厌秋 提交于 2019-12-22 03:45:17
问题 I'm using MultiMap from Google Guava 12 like this: Multimap<Integer, OccupancyType> pkgPOP = HashMultimap.create(); after inserting values into this multimap, I need to return: Map<Integer, Set<OccupancyType>> However, when I do: return pkgPOP.asMap(); It returns me Map<Integer, Collection<OccupancyType>> How can I return Map<Integer, Set<OccupancyType>> instead ? 回答1: Look at this issue and comment #2 by Kevin Bourrillion, head Guava dev: You can double-cast the Map<K, Collection<V>> first

removing duplicates of a list of sets

柔情痞子 提交于 2019-12-22 03:22:12
问题 I have a list of sets : L = [set([1, 4]), set([1, 4]), set([1, 2]), set([1, 2]), set([2, 4]), set([2, 4]), set([5, 6]), set([5, 6]), set([3, 6]), set([3, 6]), set([3, 5]), set([3, 5])] (actually in my case a conversion of a list of reciprocal tuples) and I want to remove duplicates to get : L = [set([1, 4]), set([1, 2]), set([2, 4]), set([5, 6]), set([3, 6]), set([3, 5])] But if I try : >>> list(set(L)) TypeError: unhashable type: 'set' Or >>> list(np.unique(L)) TypeError: cannot compare sets