作者ric2k1 (Ric)
看板EE_DSnP
標題Re: [問題] myHash.h
時間Sun Jun 21 19:57:44 2009
※ 引述《uxijgil ()》之銘言:
: 問一下一些觀念
: 1. 關於Hash iterator end()
: 這裡 pass the end 是指...
: 指向 最後一個有效元素 的後面(ex: null) ?
1F:推 Peter034:其實end()代表哪裡不很重要,只要能判斷iterator!=end()06/21 04:58
2F:→ Peter034:還有要能讓空的時候 begin() == end()06/21 04:59
推文觀念正確
: 2. 關於 Hash iterator ++ or --
: 我們可以假設它不會超過 end() or 來到begin()更前面 ?
: 也就是說 , 在操作的時候 , 只會讓他到達 end() 就停 , 不會再故意更前進 ?
可以
: 除此之外 , 在等於begin()的時候 , 不會再刻意地往前 ?
: 還是說 , 我們要額外把這種情況考慮進去 ?
事實上, 因為 begin() 不一定指到第 0 個 bucket 的第 0 個元素,
因此, 較正確的作法是 -- 可以超過 begin() 而停在 pass-the-begin 的 element 上
但是我想這點當初 spec 沒有定義清楚, 所以大家就自行定義好了, 我們只會測 ++
: 3. 如果 Hash 現在一個有效元素都沒有
: 這時候要讓 begin() = end() ?
Yes
: 4. 關於 Hash function or Cache function
: Hash or Cache function 的實現是要在 Hash or Cache 的 class 下運作 ?
: 否則好像沒辦法 Access 到 size的資訊
: 是要利用類似 bucketNum(...) 來算出落在哪一欄嗎 ? (感覺像這樣...?)
: 所以Cache那邊其實也是要自己加一個類似的 cacheNum(...) ?
Because Hash & Cache is used as a container class,
the Hash & Cache functions should be defined in the scope of the
HashKey/CacheKey. Actually Hash & Cache functions are the overloaded ()
operators in the HashKey/CacheKey classes.
The Hash and Cache functions return a size_t, NOT a number between
Hash::_numBuckets or Cache::_size. It is modulated by the Hash::_numBuckets
or Cache::_size WITHIN the Hash and Cache classes for the bucket index.
The Hash/Cache functions should be independent of the Hash::_numBuckets
or Cache::_size. That is, the HashKey/CacheKey should not be aware of the
Hash::_numBuckets or Cache::_size because the Hash::_numBuckets or
Cache::_size may change while the Hash & Cache functions should remain the
same for the same type of HashKey/CacheKey.
: 麻煩了 , 謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.224.46.108
3F:推 uxijgil:謝謝 , 明白了 ! 06/21 21:23