2 * Copyright 2009-2013, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
5 #ifndef _PACKAGE__HPKG__PRIVATE__STRINGS_H_
6 #define _PACKAGE__HPKG__PRIVATE__STRINGS_H_
11 #include <util/OpenHashTable.h>
14 namespace BPackageKit
{
21 uint32
hash_string(const char* string
);
28 CachedString
* next
; // hash table link
43 bool Init(const char* string
)
45 this->string
= strdup(string
);
46 if (this->string
== NULL
)
54 struct CachedStringHashDefinition
{
55 typedef const char* KeyType
;
56 typedef CachedString ValueType
;
58 size_t HashKey(const char* key
) const
60 return hash_string(key
);
63 size_t Hash(const CachedString
* value
) const
65 return HashKey(value
->string
);
68 bool Compare(const char* key
, const CachedString
* value
) const
70 return strcmp(value
->string
, key
) == 0;
73 CachedString
*& GetLink(CachedString
* value
) const
80 typedef BOpenHashTable
<CachedStringHashDefinition
> CachedStringTable
;
83 struct CachedStringUsageGreater
{
84 bool operator()(const CachedString
* a
, const CachedString
* b
)
86 return a
->usageCount
> b
->usageCount
;
91 struct StringCache
: public CachedStringTable
{
95 CachedString
* Get(const char* value
);
96 void Put(CachedString
* string
);
100 } // namespace BPrivate
104 } // namespace BPackageKit
107 #endif // _PACKAGE__HPKG__PRIVATE__STRINGS_H_