unordered

C++ std::tr1::hash for a templated class

↘锁芯ラ 提交于 2019-12-10 14:36:04
问题 I have this templated class: template <typename T> Thing { ... }; and I would like to use it in an unordered_set: template <typename T> class Bozo { typedef unordered_set<Thing<T> > things_type; things_type things; ... }; Now class Thing has everything it needs except a hash function. I would like to make this generic so I try something like: namespace std { namespace tr1 { template <typename T> size_t hash<Thing<T> >::operator()(const Thing<T> &t) const { ... } }} Attempts to compile this

Finding Sub-Strings of String Containing all the words in array

老子叫甜甜 提交于 2019-12-05 04:06:54
问题 I have a String and an array of words and I have to write code to find all substrings of the string that contain all the words in the array in any order. The string does not contain any special characters / digits and each word is separated by a space. For example: String given: aaaa aaaa aaaa aaaa cccc bbbb bbbb bbbb bbbb aaaa bbbb cccc Words in array: aaaa bbbb cccc Sample of output: aaaa aaaa aaaa aaaa cccc bbbb bbbb bbbb bbbb aaaa aaaa aaaa aaaa cccc bbbb aaaa cccc bbbb bbbb bbbb bbbb

Multilevel JSON diff in python

99封情书 提交于 2019-12-02 01:58:42
Please link me to answer if this has already been answered, my problem is i want to get diff of multilevel json which is unordered. x=json.loads('''[{"y":2,"x":1},{"x":3,"y":4}]''') y=json.loads('''[{"x":1,"y":2},{"x":3,"y":4}]''') z=json.loads('''[{"x":3,"y":4},{"x":1,"y":2}]''') import json_tools as jt import json_delta as jd print jt.diff(y,z) print jd.diff(y,z) print y==z print x==y output is [{'prev': 2, 'value': 4, 'replace': u'/0/y'}, {'prev': 1, 'value': 3, 'replace': u'/0/x'}, {'prev': 4, 'value': 2, 'replace': u'/1/y'}, {'prev': 3, 'value': 1, 'replace': u'/1/x'}] [[[2], {u'y': 2, u