static n_object * object_end_or_find(n_object * object, n_string name) { n_object * previous_object = 0L; n_uint hash = math_hash((n_byte *)name, io_length(name, STRING_BLOCK_SIZE)); if (object == 0L) { return 0L; } do { if (hash == object->name_hash) { return previous_object; } previous_object = object; object = object->primitive.next; }while (object); return previous_object; }
static n_object * obj_get(n_object * object, n_string name) { n_object * set_object; n_int string_length = io_length(name, STRING_BLOCK_SIZE); n_uint hash = math_hash((n_byte *)name, string_length); if (object == 0L) { object = object_new(); } if (object_type(&object->primitive) == OBJECT_EMPTY) { set_object = object; } else { n_object * previous_object = object_end_or_find(object, name); if (previous_object == 0L) { set_object = object; } else { set_object = previous_object->primitive.next; if (set_object == 0L) { set_object = object_new(); } previous_object->primitive.next = set_object; } } set_object->name = name; set_object->name_hash = hash; return set_object; }
int main(int argc, const char * argv[]) { n_int counter = 0; printf(" --- test sim --- start -----------------------------------------------\n"); sim_init(2, 0x12738291, MAP_AREA, 0); { noble_simulation * local_sim = sim_sim(); noble_being * first_being = &(local_sim->beings[0]); noble_being * second_being = &(local_sim->beings[1]); noble_being_constant * first_being_constant = &(first_being->constant); noble_being_delta * first_being_delta = &(first_being->delta); noble_being_events * first_being_events = &(first_being->events); noble_being_brain * first_being_brain = &(first_being->braindata); noble_immune_system * first_being_immune = &(first_being->immune_system); noble_being_volatile * first_being_volatile = &(first_being->changes); n_uint being_hash1 = math_hash((n_byte *)first_being, sizeof(noble_being)); n_uint being_constant_hash1 = math_hash((n_byte *)first_being_constant, sizeof(noble_being_constant)); n_uint being_delta_hash1 = math_hash((n_byte *)first_being_delta, sizeof(noble_being_delta)); n_uint being_events_hash1 = math_hash((n_byte *)first_being_events, sizeof(noble_being_events)); n_uint being_brain_hash1 = math_hash((n_byte *)first_being_brain, sizeof(noble_being_brain)); n_uint being_immune_hash1 = math_hash((n_byte*)first_being_immune, sizeof(noble_immune_system)); n_uint being_volatile_hash1 = math_hash((n_byte*)first_being_volatile, sizeof(noble_being_volatile)); while (counter < 1000) { sim_cycle(); counter ++; } n_uint being_hash2 = math_hash((n_byte *)first_being, sizeof(noble_being)); n_uint being_constant_hash2 = math_hash((n_byte *)first_being_constant, sizeof(noble_being_constant)); n_uint being_delta_hash2 = math_hash((n_byte *)first_being_delta, sizeof(noble_being_delta)); n_uint being_events_hash2 = math_hash((n_byte *)first_being_events, sizeof(noble_being_events)); n_uint being_brain_hash2 = math_hash((n_byte *)first_being_brain, sizeof(noble_being_brain)); n_uint being_immune_hash2 = math_hash((n_byte*)first_being_immune, sizeof(noble_immune_system)); n_uint being_volatile_hash2 = math_hash((n_byte*)first_being_volatile, sizeof(noble_being_volatile)); printf("hash %lx\n", being_hash1 ^ being_hash2); printf("constant %lx\n", being_constant_hash1 ^ being_constant_hash2); printf("delta %lx\n", being_delta_hash1 ^ being_delta_hash2); printf("events %lx\n", being_events_hash1 ^ being_events_hash2); printf("brain %lx\n", being_brain_hash1 ^ being_brain_hash2); printf("immune %lx\n", being_immune_hash1 ^ being_immune_hash2); printf("volatile %lx\n", being_volatile_hash1 ^ being_volatile_hash2); } sim_close(); printf(" --- test sim --- end -----------------------------------------------\n"); return 1; }
struct math *math_hash_lookup(register const char *str, register unsigned int len) { enum { TOTAL_KEYWORDS = 31, MIN_WORD_LENGTH = 2, MAX_WORD_LENGTH = 9, MIN_HASH_VALUE = 2, MAX_HASH_VALUE = 64 }; static unsigned char lengthtable[] = { 0, 0, 2, 3, 0, 2, 3, 0, 3, 4, 2, 3, 0, 3, 4, 0, 3, 0, 3, 9, 0, 6, 0, 3, 6, 0, 3, 0, 3, 4, 0, 0, 2, 3, 0, 0, 6, 7, 3, 0, 0, 6, 0, 3, 4, 0, 6, 0, 3, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4 }; static struct math wordlist[] = { {"", NULL}, {"", NULL}, #line 84 "lmathtab.gperf" {"EQ", math_eq}, #line 85 "lmathtab.gperf" {"NEQ", math_neq}, {"", NULL}, #line 82 "lmathtab.gperf" {"GT", math_gt}, #line 83 "lmathtab.gperf" {"GTE", math_gte}, {"", NULL}, #line 64 "lmathtab.gperf" {"MIN", math_min}, #line 75 "lmathtab.gperf" {"MEAN", math_mean}, #line 80 "lmathtab.gperf" {"LT", math_lt}, #line 81 "lmathtab.gperf" {"LTE", math_lte}, {"", NULL}, #line 66 "lmathtab.gperf" {"AND", math_and}, #line 67 "lmathtab.gperf" {"NAND", math_nand}, {"", NULL}, #line 57 "lmathtab.gperf" {"MUL", math_mul}, {"", NULL}, #line 65 "lmathtab.gperf" {"MAX", math_max}, #line 63 "lmathtab.gperf" {"REMAINDER", math_remainder}, {"", NULL}, #line 76 "lmathtab.gperf" {"MEDIAN", math_median}, {"", NULL}, #line 69 "lmathtab.gperf" {"NOR", math_nor}, #line 77 "lmathtab.gperf" {"STDDEV", math_stddev}, {"", NULL}, #line 56 "lmathtab.gperf" {"SUB", math_sub}, {"", NULL}, #line 60 "lmathtab.gperf" {"MOD", math_modulo}, #line 71 "lmathtab.gperf" {"BAND", math_band}, {"", NULL}, {"", NULL}, #line 68 "lmathtab.gperf" {"OR", math_or}, #line 58 "lmathtab.gperf" {"DIV", math_div}, {"", NULL}, {"", NULL}, #line 61 "lmathtab.gperf" {"MODULO", math_modulo}, #line 62 "lmathtab.gperf" {"MODULUS", math_modulo}, #line 72 "lmathtab.gperf" {"BOR", math_bor}, {"", NULL}, {"", NULL}, #line 79 "lmathtab.gperf" {"DIST3D", math_dist3d}, {"", NULL}, #line 55 "lmathtab.gperf" {"ADD", math_add}, #line 73 "lmathtab.gperf" {"BXOR", math_bxor}, {"", NULL}, #line 78 "lmathtab.gperf" {"DIST2D", math_dist2d}, {"", NULL}, #line 70 "lmathtab.gperf" {"XOR", math_xor}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}, #line 59 "lmathtab.gperf" {"FLOORDIV", math_floordiv}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}, {"", NULL}, #line 74 "lmathtab.gperf" {"FDIV", math_fdiv} }; if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) { register int key = math_hash(str, len); if (key <= MAX_HASH_VALUE && key >= 0) if (len == lengthtable[key]) { register const char *s = wordlist[key].name; if ((((unsigned char) *str ^ (unsigned char) *s) & ~32) == 0 && !gperf_case_memcmp(str, s, len)) return &wordlist[key]; } } return 0; }