137b74a387bb3993387029859c2d9d051c41c724eStephen Hines//===- HashEntry.h --------------------------------------------------------===// 25460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 35460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// The MCLinker Project 45460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 55460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// This file is distributed under the University of Illinois Open Source 65460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// License. See LICENSE.TXT for details. 75460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// 85460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===// 95460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 1037b74a387bb3993387029859c2d9d051c41c724eStephen Hines#ifndef MCLD_ADT_HASHENTRY_H_ 1137b74a387bb3993387029859c2d9d051c41c724eStephen Hines#define MCLD_ADT_HASHENTRY_H_ 125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 135460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaonamespace mcld { 145460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 155460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/** forward declaration **/ 1637b74a387bb3993387029859c2d9d051c41c724eStephen Hinestemplate <typename HashEntryTy> 175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass EntryFactory; 185460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 195460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/** \class HashEntry 205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * \brief HashEntry is the item in the bucket of hash table. 215460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * 225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * mcld::HashEntry illustrates the demand from mcld::HashTable. 235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * Since HashTable can change the definition of the HashEntry by changing 245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * the template argument. class mcld::HashEntry here is used to show the 255460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * basic interfaces that HashTable requests. You can define your own entry 265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * of the hash table which has no relation to mcld::HashEntry 275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * 285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * Since mcld::HashEntry here is a special class whose size is changing, 295460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * derive a new class from it is risky. Make sure you understand what you 305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao * are doing when you let a new class inherit from mcld::HashEntry. 315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao */ 325460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaotemplate <typename KeyType, typename ValueType, typename KeyCompare> 3337b74a387bb3993387029859c2d9d051c41c724eStephen Hinesclass HashEntry { 3437b74a387bb3993387029859c2d9d051c41c724eStephen Hines public: 355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao typedef KeyType key_type; 365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao typedef ValueType value_type; 375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao typedef KeyCompare key_compare; 385460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 3937b74a387bb3993387029859c2d9d051c41c724eStephen Hines private: 405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao typedef HashEntry<KeyType, ValueType, KeyCompare> Self; 415460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao friend class EntryFactory<Self>; 425460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 4337b74a387bb3993387029859c2d9d051c41c724eStephen Hines private: 4437b74a387bb3993387029859c2d9d051c41c724eStephen Hines explicit HashEntry(const KeyType& pKey); 455460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ~HashEntry(); 465460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 4737b74a387bb3993387029859c2d9d051c41c724eStephen Hines public: 4837b74a387bb3993387029859c2d9d051c41c724eStephen Hines KeyType& key() { return m_Key; } 495460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 5037b74a387bb3993387029859c2d9d051c41c724eStephen Hines const KeyType& key() const { return m_Key; } 515460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 5237b74a387bb3993387029859c2d9d051c41c724eStephen Hines ValueType& value() { return m_Value; } 535460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 5437b74a387bb3993387029859c2d9d051c41c724eStephen Hines const ValueType& value() const { return m_Value; } 555460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 5637b74a387bb3993387029859c2d9d051c41c724eStephen Hines void setValue(const ValueType& pValue) { m_Value = pValue; } 575460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 585460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao bool compare(const key_type& pKey); 595460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 6037b74a387bb3993387029859c2d9d051c41c724eStephen Hines public: 615460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao KeyType m_Key; 625460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ValueType m_Value; 635460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao}; 645460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 655460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaotemplate <typename HashEntryTy> 6637b74a387bb3993387029859c2d9d051c41c724eStephen Hinesclass EntryFactory { 6737b74a387bb3993387029859c2d9d051c41c724eStephen Hines public: 6837b74a387bb3993387029859c2d9d051c41c724eStephen Hines typedef HashEntryTy entry_type; 6937b74a387bb3993387029859c2d9d051c41c724eStephen Hines typedef typename HashEntryTy::key_type key_type; 705460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao typedef typename HashEntryTy::value_type value_type; 715460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 7237b74a387bb3993387029859c2d9d051c41c724eStephen Hines public: 735460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao EntryFactory(); 745460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao ~EntryFactory(); 755460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 765460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao HashEntryTy* produce(const key_type& pKey); 775460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao void destroy(HashEntryTy* pEntry); 785460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao}; 795460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 805460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include "HashEntry.tcc" 815460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao 8237b74a387bb3993387029859c2d9d051c41c724eStephen Hines} // namespace mcld 83affc150dc44fab1911775a49636d0ce85333b634Zonr Chang 8437b74a387bb3993387029859c2d9d051c41c724eStephen Hines#endif // MCLD_ADT_HASHENTRY_H_ 85