2011-03-13 14 views
17

Google neden açık kaynaklı kitaplığın iki uygulaması vardır: yoğun bir karma ve seyrek bir?Seyrek hash tablosunun arkasındaki ana uygulama fikri nedir?

+0

Sanırım yazıdaki soruyu yanlış anladım. Hashtables + yoğun hashtables == tüm hashtables seyrek olmaz mıydı? Ve eğer öyleyse, o zaman neden kütüphane "sparsehash" denir? – cHao

+3

BTW: [Google Code dokümanları] (http://google-sparsehash.googlecode.com/svn/trunk/doc/implementation.html). – cHao

cevap

16

Yoğun hashtable olağan ders kitabı karma uygulamanızdır.

Seyrek hashtable yalnızca bir dizi dizide bölünmüş, gerçekten ayarlanmış öğeleri saklar. seyrek tablolar uygulanmasında comments alıntı için: her unsur yükü doğurur ki

// To store the sparse array, we store a bitmap B, where B[i] = 1 iff 
// bucket i is non-empty. Then to look up bucket i we really look up 
// array[# of 1s before i in B]. This is constant time for fixed M. 

:

// The idea is that a table with (logically) t buckets is divided 
// into t/M *groups* of M buckets each. (M is a constant set in 
// GROUP_SIZE for efficiency.) Each group is stored sparsely. 
// Thus, inserting into the table causes some array to grow, which is 
// slow but still constant time. Lookup involves doing a 
// logical-position-to-sparse-position lookup, which is also slow but 
// constant time. The larger M is, the slower these operations are 
// but the less overhead (slightly). 

dizi elemanları ayarlanır olan uygulamaları öğrenmek için seyrek tablo bir bit eşlem içerir sadece 1 bit (sınırda).

3

sparsehash, anahtarların değerlere eşleştirilmesinin (anahtar başına 1-2 bit) bellek açısından verimli bir yoludur. Bloom filtreleri size anahtar başına daha az sayıda bit verebilir, ancak dışardan/muhtemelen içeriden başka bir bilgi değerinden biraz daha az olan tuşlara değerler eklemezler.