You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

84 lines
3.0 KiB

#ifndef MODGMT_COLORNAMES_H
#define MODGMT_COLORNAMES_H
struct colorname {const char *name; double r; double g; double b; };
#include <string.h>
class ColorHash
{
private:
static inline unsigned int colornamehash (const char *str, unsigned int len);
public:
static const struct colorname *in_colors_set (const char *str, unsigned int len);
};
inline unsigned int
ColorHash::colornamehash (const char *str, unsigned int len)
{
static const unsigned short asso_values[] =
{
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 666, 27,
26, 23, 22, 789, 588, 587, 501, 436, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 61, 96, 222, 98, 22,
117, 22, 561, 559, 22, 708, 179, 301, 42, 101,
242, 46, 23, 22, 116, 171, 821, 809, 2728, 169,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 61, 96, 222,
98, 22, 117, 22, 561, 559, 22, 708, 179, 301,
42, 101, 242, 46, 23, 22, 116, 171, 821, 809,
2728, 169, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728, 2728,
2728, 2728, 2728, 2728, 2728, 2728
};
int hval = len;
switch (hval)
{
default:
hval += asso_values[(unsigned char)str[12]];
/*FALLTHROUGH*/
case 12:
hval += asso_values[(unsigned char)str[11]];
/*FALLTHROUGH*/
case 11:
case 10:
case 9:
case 8:
hval += asso_values[(unsigned char)str[7]];
/*FALLTHROUGH*/
case 7:
hval += asso_values[(unsigned char)str[6]];
/*FALLTHROUGH*/
case 6:
hval += asso_values[(unsigned char)str[5]];
/*FALLTHROUGH*/
case 5:
hval += asso_values[(unsigned char)str[4]];
/*FALLTHROUGH*/
case 4:
case 3:
hval += asso_values[(unsigned char)str[2]];
/*FALLTHROUGH*/
case 2:
case 1:
hval += asso_values[(unsigned char)str[0]];
break;
}
return hval + asso_values[(unsigned char)str[len - 1]];
}
#endif