P**********c 发帖数: 3417 | 1 假设是用C/C++, 不会Java. C/C++没有很方便的hash table可用,怎么办呢?比如说要
hash一堆浮点数或者一堆string, 是不是还要自己想一个hash function呢。但是自己
想的function肯定又有collision问题和有一些空间空着的问题,感觉white board很不
好写啊。
C++的map是BST, runtime完全不对啊。大家怎么解决这个问题的。 |
S**I 发帖数: 15689 | 2 Both MSVC and GCC provide hash_map and C++0x has unordered_map.
【在 P**********c 的大作中提到】 : 假设是用C/C++, 不会Java. C/C++没有很方便的hash table可用,怎么办呢?比如说要 : hash一堆浮点数或者一堆string, 是不是还要自己想一个hash function呢。但是自己 : 想的function肯定又有collision问题和有一些空间空着的问题,感觉white board很不 : 好写啊。 : C++的map是BST, runtime完全不对啊。大家怎么解决这个问题的。
|
P**********c 发帖数: 3417 | 3 就是说可用了?
【在 S**I 的大作中提到】 : Both MSVC and GCC provide hash_map and C++0x has unordered_map.
|
n**e 发帖数: 116 | 4 You may use std::tr1::unordered_map as a HashTable. E.g.,
typedef std::tr1::unordered_map HashTable;
HashTable months;
months["january"] = 31;
months["february"] = 28;
months["march"] = 31; |
i**********e 发帖数: 1145 | 5 大概知道这三个就行了,函数可以自由定义,白版 coding 大概跟面试官沟通下就行。
hash_set --> for recording if an element exists in set (no multiples
allowed)
hash_map --> for one-to-one mapping an element of type T1 to T2. (no
duplicate key is allowed, inserting a key which already exists will be
ignored; however you can overwrite the value using the returned iterator
from insert() function)
hash_multimap --> for one-to-many mapping an element of type T1 to
element(s) of type T2. Duplicates are allowed.
【在 P**********c 的大作中提到】 : 假设是用C/C++, 不会Java. C/C++没有很方便的hash table可用,怎么办呢?比如说要 : hash一堆浮点数或者一堆string, 是不是还要自己想一个hash function呢。但是自己 : 想的function肯定又有collision问题和有一些空间空着的问题,感觉white board很不 : 好写啊。 : C++的map是BST, runtime完全不对啊。大家怎么解决这个问题的。
|
P**********c 发帖数: 3417 | 6 赞,很详细。
no
【在 i**********e 的大作中提到】 : 大概知道这三个就行了,函数可以自由定义,白版 coding 大概跟面试官沟通下就行。 : hash_set --> for recording if an element exists in set (no multiples : allowed) : hash_map --> for one-to-one mapping an element of type T1 to T2. (no : duplicate key is allowed, inserting a key which already exists will be : ignored; however you can overwrite the value using the returned iterator : from insert() function) : hash_multimap --> for one-to-many mapping an element of type T1 to : element(s) of type T2. Duplicates are allowed.
|