xref: /haiku/src/add-ons/kernel/file_systems/ext2/HashRevokeManager.h (revision 68ea01249e1e2088933cb12f9c28d4e5c5d1c9ef)
1 /*
2  * Copyright 2001-2010, Haiku Inc. All rights reserved.
3  * This file may be used under the terms of the MIT License.
4  *
5  * Authors:
6  *		Janito V. Ferreira Filho
7  */
8 #ifndef HASHREVOKEMANAGER_H
9 #define HASHREVOKEMANAGER_H
10 
11 #include <util/OpenHashTable.h>
12 
13 #include "RevokeManager.h"
14 
15 
16 struct RevokeElement {
17 	RevokeElement*	next;	// Next in hash
18 	uint32			block;
19 	uint32			commitID;
20 };
21 
22 
23 struct RevokeHash {
24 		typedef uint32			KeyType;
25 		typedef	RevokeElement	ValueType;
26 
27 		size_t HashKey(KeyType key) const
28 		{
29 			return key;
30 		}
31 
32 		size_t Hash(ValueType* value) const
33 		{
34 			return HashKey(value->block);
35 		}
36 
37 		bool Compare(KeyType key, ValueType* value) const
38 		{
39 			return value->block == key;
40 		}
41 
42 		ValueType*& GetLink(ValueType* value) const
43 		{
44 			return value->next;
45 		}
46 
47 };
48 
49 typedef BOpenHashTable<RevokeHash> RevokeTable;
50 
51 
52 class HashRevokeManager : public RevokeManager {
53 public:
54 						HashRevokeManager(bool has64bits);
55 	virtual				~HashRevokeManager();
56 
57 			status_t	Init();
58 
59 	virtual	status_t	Insert(uint32 block, uint32 commitID);
60 	virtual	status_t	Remove(uint32 block);
61 	virtual	bool		Lookup(uint32 block, uint32 commitID);
62 
63 	static	int			Compare(void* element, const void* key);
64 	static	uint32		Hash(void* element, const void* key, uint32 range);
65 
66 protected:
67 			status_t	_ForceInsert(uint32 block, uint32 commitID);
68 
69 private:
70 			RevokeTable*	fHash;
71 
72 	const	int			kInitialHashSize;
73 };
74 
75 #endif	// HASHREVOKEMANAGER_H
76 
77