c++ - Developing a Hashing Algorithm: RGB Color ID and String to Int -


in program writing, develop hashing algorithm can map either rgb color, string, or both unique , relatively small index.

the goal here reduce many collisions possible, guarantee no 2 colors being passed through algorithm similar (perceptually; e.g. red, blue, orange).

with limited knowledge, array seems optimal choice direct-access data structure, not want create incredibly large array. given have allocate memory in c++ array, having trouble developing such algorithm.

any tips appreciated!

you use std::map access subject color or label. no need develop own hashing algorithms that, have create comparison operator, should easy on case, assuming use 32bit integer rgb color, , std::string label.

edit: dont need make else map (no custom operators), simple as:

typedef map<int, myclass*, greater<int> > intclassmap; typedef map<std::string, myclass*, greater<std::string> > strclassmap; intclassmap inttable; strclassmap strtable; void adding_the_data(){ inttable[0x11223344] = myclasspointer1; inttable[0x11223345] = myclasspointer2; inttable[0x11223346] = myclasspointer3; strtable["test string1"] = myclasspointer1; strtable["test string2"] = myclasspointer2; strtable["test string3"] = myclasspointer3; } void accessing_example(){ strtable["test string1"]->something; } 

std::map fast, don't think need (or find) faster solution that.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -