What's the difference between grep and map in Perl?
In Perl both grep and map take an expression and a list, and evaluate the expression for each element of the list. What is the difference between the two? ...
In Perl both grep and map take an expression and a list, and evaluate the expression for each element of the list. What is the difference between the two? ...
I am using TreeBidiMap from the apache collections library. I want to sort this on the values which are doubles. My method is to retrieve a Collection view of the values using Collection coll = themap.values(). Which naturally works fine. Main Question: I now want to know how I can convert/cast (not sure which is correct) coll into a Li...
Hi, Can you please tell me what I can use in C# as an equivalent to TreeBidiMap from Commons Collections in Java. Thanks ...
In Ruby, what is the most expressive way to map an array in such a way that certain elements are modified and the others left untouched? This is a straight-forward way to do it: old_a = ["a", "b", "c"] # ["a", "b", "c"] new_a = old_a.map { |x| (x=="b" ? x+"!" : x) } # ["a", "b!", "c"] Omitting the "leave-alon...
With reference to this question StackoVerflow 529831, this was one of the suggested approaches template<typename Map> typename Map::const_iterator greatest_less(Map const& m, typename Map::key_type const& k) { //How to print K and Map m typename Map::const_iterator it = m.lower_bound(k); if(it != m.begin()) { return ...
Dear all, I have the following data as input (sorted by first column): foo 1 2 foo 3 3 bar 10 11 I want to create a Map of Vector with first column as key of the map such that we have: foo = {1,2,3,3} bar = {10,11} But why my code below doesn't work as expected? #include <vector> #include <map> #include <iostream> ...
I want to perform the followning task using JSF / Richfaces On click of a link - I would like to generate a PNG image with map (portion of the image should be click-able) and render under a panel. When I generate the image, I know the co-ordinates of the image which needs to be click-able. So I can generate the map. But I want to do it...
This is quite n00bish, but I'm trying to learn/understand functional programming in python. The following code: foos = [1.0,2.0,3.0,4.0,5.0] bars = [1,2,3] def maptest(foo, bar): print foo, bar map(maptest, foos, bars) produces: 1.0 1 2.0 2 3.0 3 4.0 None 5.0 None Q. Is there a way to use map or any other functional tools in ...
If I have a collection c of type T and there is a property p on T (of type P, say), what is the best way to do a map-by-extracting-key? val c: Collection[T] val m: Map[P, T] One way is the following: m = new HashMap[P, T] c foreach { t => m add (t.getP, t) } But now I need a mutable map. Is there a better way of doing this so that ...
I don't know how to extend the map object with prototype and hope you can help. I have something like this: var map = {'one':1, 'two':2}; and I would like to have a method to check for the existence of a key: if (map.containsKey('one')){...} How would I extend the map object? ...
It's a long one so you might want to get that cup of tea/coffee you've been holding off on ;) I run a game called World of Arl, it's a turn based strategy game akin to Risk or Diplomacy. Each player has a set of cities, armies and whatnot. The question revolves around the display of these things. Currently the map is created using a bac...
Hi, I'm trying to use an enum as a mapkey for a map in Hibernate, but Hibernate stores my enum as a RAW: I have this enum: public enum AccountType implements Serializable { CASH, CREDIT_CARD, GIRO, INVOICE, OTHER; } Which I'm trying to use as a key in a map: @CollectionOfElements @MapKey(columns = @Column(name=...
I was writing an algorithm this morning and I ran into a curious situation. I have two std::maps. I want to perform a set intersection on the sets of the keys of each (to find which keys are common to both maps). At some point in the future, I think it's likely I'll also want to perform set subtraction here as well. Luckily, the STL ...
I'm looking for a class in java that has key-value association, but without using hashes. Here is what I'm currently doing: Add values to a Hashtable Get an iterator for the Hashtable.entrySet(). Iterate through all values and: Get a Map.Entry for the iterator Create an object of type Module (a custom class) based on the value. Add t...
What's the best way in C++ to copy a pair from a map to vector? I'm doing this so I can subsequently sort the vector. ...
Quick background I have a concurrent map I used to cache some values that change quite often (still worth caching them from testing). I want to evict items from my cache at regular intervals by examining an expire time in the value. I am using the keySet() method to get a reference to all my keys and then check the values and if expired ...
I have a class called ImageMatrix, which implements the C++ map in a recursive fashion; the end result is that I have a 3 dimensional array. typedef uint32_t VUInt32; typedef int32_t VInt32; class ImageMatrix { public: ImageMatrixRow operator[](VInt32 rowIndex) private: ImageMatrixRowMap rows; }; typedef std::map <VUInt32, VIn...
See also http://stackoverflow.com/questions/695372/c-standard-list-and-default-constructible-types Not a major issue, just annoying as I don't want my class to ever be instantiated without the particular arguments. class MyClass { public: MyClass(MyType1 t); MyType2 &operator[](int index); } map<int, MyClass> myMap; Th...
Regarding the C++ STL map, erasing by key:- size_type map::erase ( const key_type& x ); Is it legal to erase a non-existing key? i.e. is the snippet below ok? map<char,int> mymap; mymap['c']=30; mymap.erase('c'); mymap.erase('c'); mymap.erase('D'); Cheers ...
Map type from STL have next type: std::map< Key, Data, Compare, Alloc > As one of template parameters we could pass Compare predicate, why map accept this predicate as template parameter and not as object in constructor? It could has more flexible interface with something like boost::function< bool, const T&, const T& > in constr...