123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- #ifndef __PJPP_HASH_HPP__
- #define __PJPP_HASH_HPP__
- #include <pj++/types.hpp>
- #include <pj++/pool.hpp>
- #include <pj/hash.h>
- class Pj_Hash_Table : public Pj_Object
- {
- public:
-
-
-
- class iterator
- {
- public:
- iterator()
- {
- }
- explicit iterator(pj_hash_table_t *h, pj_hash_iterator_t *i)
- : ht_(h), it_(i)
- {
- }
- iterator(const iterator &rhs)
- : ht_(rhs.ht_), it_(rhs.it_)
- {
- }
- void operator++()
- {
- it_ = pj_hash_next(ht_, it_);
- }
- bool operator==(const iterator &rhs)
- {
- return ht_ == rhs.ht_ && it_ == rhs.it_;
- }
- iterator & operator=(const iterator &rhs)
- {
- ht_=rhs.ht_; it_=rhs.it_;
- return *this;
- }
- private:
- pj_hash_table_t *ht_;
- pj_hash_iterator_t it_val_;
- pj_hash_iterator_t *it_;
- friend class Pj_Hash_Table;
- };
-
-
-
- Pj_Hash_Table(Pj_Pool *pool, unsigned size)
- {
- table_ = pj_hash_create(pool->pool_(), size);
- }
-
-
-
- ~Pj_Hash_Table()
- {
- }
-
-
-
- static pj_uint32_t calc( pj_uint32_t initial_hval,
- const void *key,
- unsigned keylen = PJ_HASH_KEY_STRING)
- {
- return pj_hash_calc(initial_hval, key, keylen);
- }
-
-
-
- pj_hash_table_t *pj_hash_table_t_()
- {
- return table_;
- }
-
-
-
- void *get(const void *key, unsigned keylen = PJ_HASH_KEY_STRING)
- {
- return pj_hash_get(table_, key, keylen);
- }
-
-
-
-
- void set(Pj_Pool *pool,
- const void *key,
- void *value,
- unsigned keylen = PJ_HASH_KEY_STRING)
- {
- pj_hash_set(pool->pool_(), table_, key, keylen, value);
- }
-
-
-
- unsigned count()
- {
- return pj_hash_count(table_);
- }
-
-
-
- iterator begin()
- {
- iterator it(table_, NULL);
- it.it_ = pj_hash_first(table_, &it.it_val_);
- return it;
- }
-
-
-
- iterator end()
- {
- return iterator(table_, NULL);
- }
- private:
- pj_hash_table_t *table_;
- };
- #endif /* __PJPP_HASH_HPP__ */
|