hash

Hashing of small dictionary

若如初见. 提交于 2020-05-31 03:46:08
问题 I want to hash small dictionary ("dictionaries/small"). Main file compiles correctly, but at runtime it produces "Segmentation fault" message with function insert() (specifically something wrong with malloc() , but I don`t know what). HASH.c #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <ctype.h> #include <string.h> typedef struct node { char* name; struct node* next; } node; node* first[26] = {NULL}; int hash(const char* buffer) { return tolower(buffer[0]) - 'a'; }

std::string_view compile time hashing

做~自己de王妃 提交于 2020-05-27 06:27:04
问题 It seems the std::hash functions for the C++17 string_view are not constexpr's. It seems to me that a string view bound to a const char[] could be hashed at compile time (which would be very sweet), or is there anything which prevents this? 回答1: Since C++14 (see 17.6.3.4 Hash requirements, table 26), we have: The value returned shall depend only on the argument k for the duration of the program. [Note: Thus all evaluations of the expression h(k) with the same value for k yield the same result

std::string_view compile time hashing

落爺英雄遲暮 提交于 2020-05-27 06:26:32
问题 It seems the std::hash functions for the C++17 string_view are not constexpr's. It seems to me that a string view bound to a const char[] could be hashed at compile time (which would be very sweet), or is there anything which prevents this? 回答1: Since C++14 (see 17.6.3.4 Hash requirements, table 26), we have: The value returned shall depend only on the argument k for the duration of the program. [Note: Thus all evaluations of the expression h(k) with the same value for k yield the same result

When to use hash tables?

岁酱吖の 提交于 2020-05-26 10:06:17
问题 What are the cases when using hash table can improve performance, and when it does not? and what are the cases when using hash tables are not applicable? 回答1: What are the cases when using hash table can improve performance, and when it does not? If you have reason to care, implement using hash tables and whatever else you're considering, put your actual data through, and measure which performs better. That said, if the hash tables has the operations you need (i.e. you're not expecting to

Accessing Swift set elements by their hash value

血红的双手。 提交于 2020-05-26 04:40:10
问题 Say I'm making a chess app, in which a position is stored like this: struct Position { var pieces: Set<Piece> // some other stuff } Piece is defined as follows: struct Piece: Hashable { var row: Int var column: Int let player: Player let type: PieceType var hashValue: Int { return 8 * row + column } } Player and PieceType are simple enums: enum Player { case White, Black } enum PieceType { case Queen, King, ... } Now, I would like to access a Piece in a Position by its position on the board.

Accessing Swift set elements by their hash value

笑着哭i 提交于 2020-05-26 04:39:50
问题 Say I'm making a chess app, in which a position is stored like this: struct Position { var pieces: Set<Piece> // some other stuff } Piece is defined as follows: struct Piece: Hashable { var row: Int var column: Int let player: Player let type: PieceType var hashValue: Int { return 8 * row + column } } Player and PieceType are simple enums: enum Player { case White, Black } enum PieceType { case Queen, King, ... } Now, I would like to access a Piece in a Position by its position on the board.

How do I search a hash table?

落爺英雄遲暮 提交于 2020-05-24 03:47:39
问题 I've just started learning about hash tables and I understand how to insert but not how to search. These are the algorithms I'll be basing this question off: Hashing the key int Hash (int key) { return key % 10; //table has a max size of 10 } Linear probing for collision resolution. Suppose I call insert twice with the keys 1, 11, and 21. This would return slot 1 for all 3 keys. After collision resolution the table would have the values 1, 11, and 21 at slots 1, 2, and 3. This is what I

How do I search a hash table?

一笑奈何 提交于 2020-05-24 03:47:25
问题 I've just started learning about hash tables and I understand how to insert but not how to search. These are the algorithms I'll be basing this question off: Hashing the key int Hash (int key) { return key % 10; //table has a max size of 10 } Linear probing for collision resolution. Suppose I call insert twice with the keys 1, 11, and 21. This would return slot 1 for all 3 keys. After collision resolution the table would have the values 1, 11, and 21 at slots 1, 2, and 3. This is what I

How to access a symbol hash key using a variable in Ruby

梦想与她 提交于 2020-05-23 07:48:11
问题 I have an array of hashes to write a generic checker for, so I want to pass in the name of a key to be checked. The hash was defined with keys with symbols (colon prefixes). I can't figure out how to use the variable as a key properly. Even though the key exists in the hash, using the variable to access it results in nil. In IRB I do this: >> family = { 'husband' => "Homer", 'wife' => "Marge" } => {"husband"=>"Homer", "wife"=>"Marge"} >> somevar = "husband" => "husband" >> family[somevar] =>

Are there any one-way hashing functions available in native JavaScript?

假如想象 提交于 2020-05-22 11:12:41
问题 I'd like to be able to create unique tokens* for users based on a hashed string. I know I could, for example, use a md5() library but as the purpose is not cryptographic I was wondering if there was anything I could use "out of the box." Are there any one-way hashing functions available in native JavaScript? *I realize these won't be strictly unique. I'm ok with a small chance of hashing collision. 回答1: not that I'm aware of. however, you could always use a JavaScript implementation of MD5