int main() { unsigned int input; unsigned int bit_length; unsigned int rng_ceil; unsigned int key_size; mpz_t key; unsigned int bits; char generate_keys = 'y'; while(is_power_of_two(rng_ceil = get_rng_ceil()) == 0) { puts("Sorry, I can only use powers of 2!"); } bit_length = get_bit_length(rng_ceil); while (generate_keys == 'y' || generate_keys == 'Y') { bits = 0; mpz_init(key); key_size = get_key_size(); while (bits < key_size) { bits += bit_length; if (bits > key_size) { mpz_mul_ui(key, key, (int) pow(2, key_size % bit_length)); mpz_add_ui(key, key, ((get_rng_input(rng_ceil)-1) & ((int) pow(2, (key_size % bit_length)+1)-1))); bits = key_size; } else { mpz_mul_ui(key, key, (int) pow(2, bit_length)); mpz_add_ui(key, key, (get_rng_input(rng_ceil)-1)); } printf("%d of %d bits generated...\n", bits, key_size); } printf("Your key is:\n0x"); mpz_out_str(stdout, 16, key); puts("\nBe sure to run this through newBitcoinKey in bitcoin.sh first if you are planning on using this to seed a Bitcoin address!"); puts("Generate another? [y/n]"); generate_keys = getchar(); while (generate_keys != 'y' && generate_keys != 'Y' && generate_keys != 'n' && generate_keys != 'N') { generate_keys = getchar(); } } return 0; }
// ----------------------------------------------------------------------------- void BLeafNode::init_restore( // load an exist node from disk to init BTree* btree, // b-tree of this node int block) // addr of disk for this node { btree_ = btree; // init <btree_> block_ = block; // init <block_> dirty_ = false; // init <dirty_> // get block length int b_length = btree_->file_->get_blocklength(); // ------------------------------------------------------------------------- // Init <capacity_keys> and calc key size // ------------------------------------------------------------------------- int key_size = get_key_size(b_length); // init <key> key_ = new float[capacity_keys_]; for (int i = 0; i < capacity_keys_; i++) { key_[i] = MINREAL; } // calc header size int header_size = get_header_size(); // calc entry size int entry_size = get_entry_size(); // init <capacity> capacity_ = (b_length - header_size - key_size) / entry_size; if (capacity_ < 100) { // at least 100 entries printf("capacity = %d\n", capacity_); error("BLeafNode::init_store capacity too small.\n", true); } id_ = new int[capacity_]; // init <id> for (int i = 0; i < capacity_; i++) { id_[i] = -1; } // ------------------------------------------------------------------------- // Read the buffer <blk> to init <level_>, <num_entries_>, <left_sibling_>, // <right_sibling_>, <num_keys_> <key_> and <id_> // ------------------------------------------------------------------------- char* blk = new char[b_length]; btree_->file_->read_block(blk, block); read_from_buffer(blk); delete[] blk; blk = NULL; }
// ----------------------------------------------------------------------------- void BLeafNode::init( // init a new node, which not exist int level, // level (depth) in b-tree BTree* btree) // b-tree of this node { btree_ = btree; // init <btree_> level_ = (char) level; // init <level_> num_entries_ = 0; // init <num_entries_> num_keys_ = 0; // init <num_keys_> left_sibling_ = -1; // init <left_sibling_> right_sibling_ = -1; // init <right_sibling_> dirty_ = true; // init <dirty_> // get block length int b_length = btree_->file_->get_blocklength(); // ------------------------------------------------------------------------- // Init <capacity_keys_> and calc key size // ------------------------------------------------------------------------- int key_size = get_key_size(b_length); // init <key> key_ = new float[capacity_keys_]; for (int i = 0; i < capacity_keys_; i++) { key_[i] = MINREAL; } // calc header size int header_size = get_header_size(); // calc entry size int entry_size = get_entry_size(); // init <capacity> capacity_ = (b_length - header_size - key_size) / entry_size; if (capacity_ < 100) { // at least 100 entries printf("capacity = %d\n", capacity_); error("BLeafNode::init capacity too small.\n", true); } id_ = new int[capacity_]; // init <id> for (int i = 0; i < capacity_; i++) { id_[i] = -1; } char* blk = new char[b_length]; // init <block> block_ = btree_->file_->append_block(blk); delete[] blk; blk = NULL; }
void CHashMap::use_node(THashNode *node, void * key, int chunk_len, BC_MEM_HANDLER chunk_head) { //set member memcpy(node->key_, key, get_key_size()); node->chunk_len_ = chunk_len; node->chunk_head_ = chunk_head; node->add_info_1_ = 0; node->add_info_2_ = 0; int bucket_list_len = get_bucket_list_len(m_get_bucket_id(node->key_)); if (bucket_list_len == 0) { //the bucket change from unused hash_map_->used_bucket_num_ ++; } insert_node_list(node); return; }
int main() { unsigned int input; unsigned int bit_length; unsigned int rng_ceil; unsigned int key_size; unsigned int bits; char generate_keys = 'y'; while(is_power_of_two(rng_ceil = get_rng_ceil()) == 0) { puts("Sorry, I can only use powers of 2!"); } bit_length = get_bit_length(rng_ceil); while (generate_keys == 'y' || generate_keys == 'Y') { bits = 0; key_size = get_key_size(); char key[BITNSLOTS(key_size)]; while (bits < key_size) { input = (get_rng_input(rng_ceil) - 1); for (int i = 0; i < bit_length && bits < key_size; i++) { if (input % 2 == 1) { BITSET(key, bits); } else { BITCLEAR(key, bits); } input = input >> 1; bits += 1; } printf("%d of %d bits generated...\n", bits, key_size); } printf("Your key is:\n0x"); unsigned int chunk = 0; for (int i = 0; i < bits; i++) { if (BITTEST(key, i)) { chunk += 1; } if (i > 0 && ((i+1) % HEXBITS == 0 || i+1 == bits)) { printf("%X", chunk); chunk = 0; } else { chunk = chunk << 1; } } puts("\nBe sure to run this through newBitcoinKey in bitcoin.sh first if you are planning on using this to seed a Bitcoin address!"); puts("Generate another? [y/n]"); generate_keys = getchar(); while (generate_keys != 'y' && generate_keys != 'Y' && generate_keys != 'n' && generate_keys != 'N') { generate_keys = getchar(); } } return 0; }