2 * Copyright 2008-2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
11 #include <util/AutoLock.h>
12 #include <util/OpenHashTable.h>
13 #include <util/StringHash.h>
16 struct EntryCacheKey
{
17 EntryCacheKey(ino_t dirID
, const char* name
)
22 hash
= (uint32
)dir_id
^ (uint32
)(dir_id
>> 32) ^ hash_hash_string(name
);
23 // We cache the hash value, so we can easily compute it before
33 struct EntryCacheEntry
{
34 EntryCacheEntry
* hash_link
;
44 struct EntryCacheGeneration
{
46 EntryCacheEntry
** entries
;
48 EntryCacheGeneration();
49 ~EntryCacheGeneration();
55 struct EntryCacheHashDefinition
{
56 typedef EntryCacheKey KeyType
;
57 typedef EntryCacheEntry ValueType
;
59 uint32
HashKey(const EntryCacheKey
& key
) const
64 size_t Hash(const EntryCacheEntry
* value
) const
66 return (uint32
)value
->dir_id
^ (uint32
)(value
->dir_id
>> 32)
67 ^ hash_hash_string(value
->name
);
70 bool Compare(const EntryCacheKey
& key
, const EntryCacheEntry
* value
) const
72 return value
->dir_id
== key
.dir_id
73 && strcmp(value
->name
, key
.name
) == 0;
76 EntryCacheEntry
*& GetLink(EntryCacheEntry
* value
) const
78 return value
->hash_link
;
90 status_t
Add(ino_t dirID
, const char* name
,
91 ino_t nodeID
, bool missing
);
93 status_t
Remove(ino_t dirID
, const char* name
);
95 bool Lookup(ino_t dirID
, const char* name
,
96 ino_t
& nodeID
, bool& missing
);
98 const char* DebugReverseLookup(ino_t nodeID
, ino_t
& _dirID
);
101 static const int32 kGenerationCount
= 8;
103 typedef BOpenHashTable
<EntryCacheHashDefinition
> EntryTable
;
104 typedef DoublyLinkedList
<EntryCacheEntry
> EntryList
;
107 void _AddEntryToCurrentGeneration(
108 EntryCacheEntry
* entry
);
113 EntryCacheGeneration fGenerations
[kGenerationCount
];
114 int32 fCurrentGeneration
;
118 #endif // ENTRY_CACHE_H