How to find value in a CMap if the key value has space in it in C++ - mfc

I have a requirement where I am storing the key, values pairs in a MFC CMap. While storing the values in this map one of the key values has a space in it and properly the key and value pairs are inserted into the CMap.
But when I am trying to find the value of a key which has space in it (two words), the value is not returned by the CMap lookup command. (if key does not have space then its working fine).
May I know how to query for the value if the key has space in it in CMap.
key here : "hello world"
value : "Test";
CMap<LPCTSTR,CString> testMap;
if(testMap.LookUp((LPCTSTR)key.MakeLower(), val))
{
}

Related

Loop through dict key equals to list than put in new list

I have a rather large dictionary right now that is set up like this:
largedict = {'journalname':{code: 2065},'journalname1':{code: 3055}}
and so on and so on. And another dictionary:
codes = {3055: 'medicine',3786: 'sciences'}
And I want to loop through largedict, compare it's code value to the keys in codes. Then either add all journalname key/value pairs that match the code to a different dictionary, or delete all that don't from largedict.
new_dic = {journal_name : journal_body for journal_name, journal_body in largedict.items() if journal_body["code"] in codes}

C++ Setting std::tuple values in an std::unordered_map

I have an unordered map with string keys and a tuple of three strings and one int. How can I access the individual tuples to set them.
Given:
std::unordered_map<string,std::tuple<string, string, string,int>> foo_data_by_username;
How can I set the individual tuple values of say foo_data_by_username[some_user];
std::get<0>(foo_data_by_username[some_user]) = "new string";
Where 0 is whichever index of the tuple you're interested in.

casting dictionary in kdb

I want to cast dictionary and log it.
dict:(enlist`code)!(enlist`B10005)
when I do
type value dict / 11h
but the key looks like ,code
when I do
type string value dict / 0h
I am not sure why.
I want to concatenate with strings and log it. So it will be something like:
"The constraint is ",string key dict
But it did not work. The constraint will be like each letter for each line. How I can cast the dictionary so I can concatenate and log it.
Have a look at http://code.kx.com/q/ref/dotq/#qs-plain-text for logging arbitrary kdb+ datatypes.
q)show dict:`key1`key2!`value1`value2
key1| value1
key2| value2
q).Q.s dict
"key1| value1\nkey2| value2\n"
There are several things are going on here.
dict has one key/value pair only but this fact doesn't affect how key and value behave: they return all keys and values. This is why type value dict is 11h which is a list of symbols. For exact same reason key dict is ,`code where comma means enlist: key dict is a list of symbols which (in your particular example) happens to have just one symbol `code.
string applied to a list of symbols converts every element of that list to a string and returns a list of strings
a string in q is a simple list of characters (see http://code.kx.com/wiki/Tutorials/Lists for more on simple and mixed lists)
when you join a simple list of characters "The constraint is " with a list of strings, i.e. a list of lists of characters a result cannot be represented as a simple list anymore and becomes a generic list. This is why q converts "The constraint is " (simple list) to ("T";"h";"e",...) (generic list) before joining and you q starts displaying each character on a separate line.
I hope you understand now what's happening. Depending on your needs you can fix your code like this:
"The constraint is ",first string key dict / displays the first key
"The constraint is ",", "sv string key dict / displays all keys separated by commas
Hope this helps.
if you are looking something for nice logging, something like this should help you(and is generic)
iterate through values, and convert to strings
s:{$[all 10h=type each x;","sv x;0h~t:type x;.z.s each x;10h~t;x;"," sv $[t<0;enlist#;(::)]string x]}/
string manipulation
fs:{((,)string[count x]," keys were passed")," " sv/:("Key:";"and the values for it were:"),'/:flip (string key#;value)#\:s each x}
examples
d:((,)`a)!(,)`a
d2:`a`b!("he";"lo")
d3:`a`b!((10 20);("he";"sss";"ssss"))
results and execution
fs each (d;d2;d3)
you can tailor obviously to your exact needs - this is not tested for complex dict values

How to implement LSH by MapReduce?

Suppose we wish to implement Local Sensitive Hashing(LSH) by MapReduce. Specifically, assume chunks of the signature matrix consist of columns, and elements are key-value pairs where the key is the column number and the value is the signature itself (i.e., a vector of values).
(a) Show how to produce the buckets for all the bands as output of a single
MapReduce process. Hint: Remember that a Map function can produce
several key-value pairs from a single element.
(b) Show how another MapReduce process can convert the output of (a) to
a list of pairs that need to be compared. Specifically, for each column i,
there should be a list of those columns j > i with which i needs to be
compared.
(a)
Map: the elements and its signature as input, produce the key-value pairs (bucket_id, element)
Reduce: produce the buckets for all the bands as output, i.e.
(bucket_id, list(elements))
map(key, value: element):
split item to bands
for band in bands:
for sig in band:
key = hash(sig) // key = bucket id
collect(key, value)
reduce(key, values):
collect(key, values)
(b)
Map: output of (a) as input, produce the list of combination in same
bucket, i.e. (bucket_id, list(elements)) -> (bucket_id,
combination(list(elements))), which combination() is any two elements
chosen from same bucket.
Reduce: output the item pairs need to be
compared, Specifically, for each column i, there should be a list of
those columns j > i with which i needs to be compared.
map(key, value):
for itemA, itemB in combinations(value)
key = (itemA.id, itemB.id)
collect(key, [itemA, itemB])
reduce(key, values):
collect(key, values)

creating empty vector to push values into later

I have a map<string,vector<string> > called dict mapping a string to a list of strings. I want to assign empty values to the values of certain keys. something like this:
else dict[words[i]]=<EMPTY VECTOR WHERE I CAN PUSH DATA LATER INTO>;
words is a vector of strings. How do I do this? Using the Standard template library of course.
else dict[words[i]]; should be sufficient on its own. If dict does not yet contain any element with a key equivalent to words[i], a new element will be created in dict with a copy of words[i] as the key and with a default constructed (empty) vector as the value.
If dict already contains an element equivalent to words[i], then dict will not be modified.
dict[words[i]] = std::vector<std::string>();