--- rxvt-unicode/src/keyboard.C 2007/07/29 09:37:01 1.27 +++ rxvt-unicode/src/keyboard.C 2010/08/23 15:58:43 1.35 @@ -51,17 +51,17 @@ * where * A1 = 0; * Ai+1 = N1 + N2 + ... + Ni. - * it is computed from hash_budget_size[]: + * it is computed from hash_bucket_size[]: * index: 0 I1 I2 I3 In * value: 0...0, N1, 0...0, N2, 0...0, N3, ..., Nn, 0...0 - * 0...0, 0.......0, N1.....N1, N1+N2...N1+N2, ... (the compution of hash[]) + * 0...0, 0.......0, N1.....N1, N1+N2...N1+N2, ... (the computation of hash[]) * or we can say - * hash_budget_size[Ii] = Ni; hash_budget_size[elsewhere] = 0, + * hash_bucket_size[Ii] = Ni; hash_bucket_size[elsewhere] = 0, * where * set {I1, I2, ..., In} = { hashkey of keymap[0]->keysym, ..., keymap[keymap.size-1]->keysym } * where hashkey of keymap[i]->keysym = keymap[i]->keysym & KEYSYM_HASH_MASK - * n(the number of groups) = the number of non-zero member of hash_budget_size[]; - * Ni(the size of group i) = hash_budget_size[Ii]. + * n(the number of groups) = the number of non-zero member of hash_bucket_size[]; + * Ni(the size of group i) = hash_bucket_size[Ii]. */ #if STOCK_KEYMAP @@ -70,7 +70,7 @@ keysym_t keyboard_manager::stock_keymap[] = { /* examples */ - /* keysym, state, range, handler, str */ + /* keysym, state, range, type, str */ //{XK_ISO_Left_Tab, 0, 1, keysym_t::STRING, "\033[Z"}, //{ 'a', 0, 26, keysym_t::RANGE_META8, "a" "%c"}, //{ 'a', ControlMask, 26, keysym_t::RANGE_META8, "" "%c"}, @@ -145,12 +145,12 @@ compare_priority (keysym_t *a, keysym_t *b) { // (the more '1's in state; the less range): the greater priority - int ca = popcount (a->state /* & OtherModMask */); - int cb = popcount (b->state /* & OtherModMask */); + int ca = rxvt_popcount (a->state /* & OtherModMask */); + int cb = rxvt_popcount (b->state /* & OtherModMask */); if (ca != cb) return ca - cb; -//else if (a->state != b->state) // this behavior is to be disscussed +//else if (a->state != b->state) // this behavior is to be discussed // return b->state - a->state; else return b->range - a->range; @@ -173,21 +173,6 @@ { keymap.clear (); hash [0] = 2; - - for (unsigned int i = 0; i < user_translations.size (); ++i) - { - free ((void *)user_translations [i]); - user_translations [i] = 0; - } - - for (unsigned int i = 0; i < user_keymap.size (); ++i) - { - delete user_keymap [i]; - user_keymap [i] = 0; - } - - user_keymap.clear (); - user_translations.clear (); } // a wrapper for register_keymap, @@ -215,7 +200,7 @@ { char *middle = strchr (translation + 5, translation [4]); char *suffix = strrchr (translation + 5, translation [4]); - + if (suffix && middle && suffix > middle + 1) { key->type = keysym_t::LIST; @@ -229,8 +214,6 @@ else if (strncmp (translation, "builtin:", 8) == 0) key->type = keysym_t::BUILTIN; - user_keymap.push_back (key); - user_translations.push_back (translation); register_keymap (key); } else @@ -380,40 +363,40 @@ { unsigned int i, index, hashkey; vector sorted_keymap; - uint16_t hash_budget_size[KEYSYM_HASH_BUDGETS]; // size of each budget - uint16_t hash_budget_counter[KEYSYM_HASH_BUDGETS]; // #elements in each budget + uint16_t hash_bucket_size[KEYSYM_HASH_BUCKETS]; // size of each bucket + uint16_t hash_bucket_counter[KEYSYM_HASH_BUCKETS]; // #elements in each bucket - memset (hash_budget_size, 0, sizeof (hash_budget_size)); - memset (hash_budget_counter, 0, sizeof (hash_budget_counter)); + memset (hash_bucket_size, 0, sizeof (hash_bucket_size)); + memset (hash_bucket_counter, 0, sizeof (hash_bucket_counter)); // determine hash bucket size for (i = 0; i < keymap.size (); ++i) - for (int j = min (keymap [i]->range, KEYSYM_HASH_BUDGETS) - 1; j >= 0; --j) + for (int j = min (keymap [i]->range, KEYSYM_HASH_BUCKETS) - 1; j >= 0; --j) { hashkey = (keymap [i]->keysym + j) & KEYSYM_HASH_MASK; - ++hash_budget_size [hashkey]; + ++hash_bucket_size [hashkey]; } - // now we know the size of each budget - // compute the index of each budget + // now we know the size of each bucket + // compute the index of each bucket hash [0] = 0; - for (index = 0, i = 1; i < KEYSYM_HASH_BUDGETS; ++i) + for (index = 0, i = 1; i < KEYSYM_HASH_BUCKETS; ++i) { - index += hash_budget_size [i - 1]; + index += hash_bucket_size [i - 1]; hash [i] = index; } // and allocate just enough space - sorted_keymap.insert (sorted_keymap.begin (), index + hash_budget_size [i - 1], 0); + sorted_keymap.insert (sorted_keymap.begin (), index + hash_bucket_size [i - 1], 0); // fill in sorted_keymap - // it is sorted in each budget + // it is sorted in each bucket for (i = 0; i < keymap.size (); ++i) - for (int j = min (keymap [i]->range, KEYSYM_HASH_BUDGETS) - 1; j >= 0; --j) + for (int j = min (keymap [i]->range, KEYSYM_HASH_BUCKETS) - 1; j >= 0; --j) { hashkey = (keymap [i]->keysym + j) & KEYSYM_HASH_MASK; - index = hash [hashkey] + hash_budget_counter [hashkey]; + index = hash [hashkey] + hash_bucket_counter [hashkey]; while (index > hash [hashkey] && compare_priority (keymap [i], sorted_keymap [index - 1]) > 0) @@ -423,17 +406,17 @@ } sorted_keymap [index] = keymap [i]; - ++hash_budget_counter [hashkey]; + ++hash_bucket_counter [hashkey]; } keymap.swap (sorted_keymap); -#ifdef DEBUG_STRICT +#ifndef NDEBUG // check for invariants - for (i = 0; i < KEYSYM_HASH_BUDGETS; ++i) + for (i = 0; i < KEYSYM_HASH_BUCKETS; ++i) { index = hash[i]; - for (int j = 0; j < hash_budget_size [i]; ++j) + for (int j = 0; j < hash_bucket_size [i]; ++j) { if (keymap [index + j]->range == 1) assert (i == (keymap [index + j]->keysym & KEYSYM_HASH_MASK)); @@ -454,8 +437,9 @@ assert (index >= 0); keysym_t *b = keymap [index]; - assert (i == (signed) index || // the normally expected result - (a->keysym + j) >= b->keysym && (a->keysym + j) <= (b->keysym + b->range) && compare_priority (a, b) <= 0); // is effectively the same or a closer match + assert (i == index // the normally expected result + || IN_RANGE_INC (a->keysym + j, b->keysym, b->keysym + b->range) + && compare_priority (a, b) <= 0); // is effectively the same or a closer match } } #endif @@ -466,8 +450,8 @@ { int hashkey = keysym & KEYSYM_HASH_MASK; unsigned int index = hash [hashkey]; - unsigned int end = hashkey < KEYSYM_HASH_BUDGETS - 1 - ? hash [hashkey + 1] + unsigned int end = hashkey < KEYSYM_HASH_BUCKETS - 1 + ? hash [hashkey + 1] : keymap.size (); for (; index < end; ++index)