ext2: migrate to BOpenHashTable.
This commit is contained in:
@@ -33,16 +33,16 @@ HashRevokeManager::~HashRevokeManager()
|
|||||||
{
|
{
|
||||||
if (fHash != NULL) {
|
if (fHash != NULL) {
|
||||||
if (fRevokeCount != 0) {
|
if (fRevokeCount != 0) {
|
||||||
RevokeElement *element =
|
RevokeElement *element = fHash->Clear(true);
|
||||||
(RevokeElement*)hash_remove_first(fHash, NULL);
|
|
||||||
|
|
||||||
while (element != NULL) {
|
while (element != NULL) {
|
||||||
|
RevokeElement* next = element->next;
|
||||||
delete element;
|
delete element;
|
||||||
element = (RevokeElement*)hash_remove_first(fHash, NULL);
|
element = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hash_uninit(fHash);
|
delete fHash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,13 +50,9 @@ HashRevokeManager::~HashRevokeManager()
|
|||||||
status_t
|
status_t
|
||||||
HashRevokeManager::Init()
|
HashRevokeManager::Init()
|
||||||
{
|
{
|
||||||
RevokeElement dummyElement;
|
fHash = new(std::nothrow) RevokeTable();
|
||||||
|
|
||||||
fHash = hash_init(kInitialHashSize, offset_of_member(dummyElement, next),
|
if (fHash == NULL || fHash->Init(kInitialHashSize) != B_OK)
|
||||||
&HashRevokeManager::Compare,
|
|
||||||
&HashRevokeManager::Hash);
|
|
||||||
|
|
||||||
if (fHash == NULL)
|
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
@@ -66,20 +62,19 @@ HashRevokeManager::Init()
|
|||||||
status_t
|
status_t
|
||||||
HashRevokeManager::Insert(uint32 block, uint32 commitID)
|
HashRevokeManager::Insert(uint32 block, uint32 commitID)
|
||||||
{
|
{
|
||||||
RevokeElement* element = (RevokeElement*)hash_lookup(fHash, &block);
|
RevokeElement* element = fHash->Lookup(block);
|
||||||
|
|
||||||
if (element != NULL) {
|
if (element != NULL) {
|
||||||
TRACE("HashRevokeManager::Insert(): Already has an element\n");
|
TRACE("HashRevokeManager::Insert(): Already has an element\n");
|
||||||
if (element->commitID < commitID) {
|
if (element->commitID < commitID) {
|
||||||
TRACE("HashRevokeManager::Insert(): Deleting previous element\n");
|
TRACE("HashRevokeManager::Insert(): Deleting previous element\n");
|
||||||
status_t retValue = hash_remove(fHash, element);
|
bool retValue = fHash->Remove(element);
|
||||||
|
|
||||||
if (retValue != B_OK)
|
if (!retValue)
|
||||||
return retValue;
|
return B_ERROR;
|
||||||
|
|
||||||
delete element;
|
delete element;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
// We already have a newer version of the block
|
// We already have a newer version of the block
|
||||||
}
|
}
|
||||||
@@ -92,24 +87,24 @@ HashRevokeManager::Insert(uint32 block, uint32 commitID)
|
|||||||
status_t
|
status_t
|
||||||
HashRevokeManager::Remove(uint32 block)
|
HashRevokeManager::Remove(uint32 block)
|
||||||
{
|
{
|
||||||
RevokeElement* element = (RevokeElement*)hash_lookup(fHash, &block);
|
RevokeElement* element = fHash->Lookup(block);
|
||||||
|
|
||||||
if (element == NULL)
|
if (element == NULL)
|
||||||
return B_ERROR; // TODO: Perhaps we should just ignore?
|
return B_ERROR; // TODO: Perhaps we should just ignore?
|
||||||
|
|
||||||
status_t retValue = hash_remove(fHash, element);
|
bool retValue = fHash->Remove(element);
|
||||||
|
|
||||||
if (retValue == B_OK)
|
if (retValue)
|
||||||
delete element;
|
delete element;
|
||||||
|
|
||||||
return retValue;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
HashRevokeManager::Lookup(uint32 block, uint32 commitID)
|
HashRevokeManager::Lookup(uint32 block, uint32 commitID)
|
||||||
{
|
{
|
||||||
RevokeElement* element = (RevokeElement*)hash_lookup(fHash, &block);
|
RevokeElement* element = fHash->Lookup(block);
|
||||||
|
|
||||||
if (element == NULL)
|
if (element == NULL)
|
||||||
return false;
|
return false;
|
||||||
@@ -157,7 +152,7 @@ HashRevokeManager::_ForceInsert(uint32 block, uint32 commitID)
|
|||||||
element->block = block;
|
element->block = block;
|
||||||
element->commitID = commitID;
|
element->commitID = commitID;
|
||||||
|
|
||||||
status_t retValue = hash_insert_grow(fHash, element);
|
status_t retValue = fHash->Insert(element);
|
||||||
|
|
||||||
if (retValue == B_OK) {
|
if (retValue == B_OK) {
|
||||||
fRevokeCount++;
|
fRevokeCount++;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#ifndef HASHREVOKEMANAGER_H
|
#ifndef HASHREVOKEMANAGER_H
|
||||||
#define HASHREVOKEMANAGER_H
|
#define HASHREVOKEMANAGER_H
|
||||||
|
|
||||||
#include <util/khash.h>
|
#include <util/OpenHashTable.h>
|
||||||
|
|
||||||
#include "RevokeManager.h"
|
#include "RevokeManager.h"
|
||||||
|
|
||||||
@@ -20,6 +20,35 @@ struct RevokeElement {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct RevokeHash {
|
||||||
|
typedef uint32 KeyType;
|
||||||
|
typedef RevokeElement ValueType;
|
||||||
|
|
||||||
|
size_t HashKey(KeyType key) const
|
||||||
|
{
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t Hash(ValueType* value) const
|
||||||
|
{
|
||||||
|
return HashKey(value->block);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Compare(KeyType key, ValueType* value) const
|
||||||
|
{
|
||||||
|
return value->block == key;
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueType*& GetLink(ValueType* value) const
|
||||||
|
{
|
||||||
|
return value->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef BOpenHashTable<RevokeHash> RevokeTable;
|
||||||
|
|
||||||
|
|
||||||
class HashRevokeManager : public RevokeManager {
|
class HashRevokeManager : public RevokeManager {
|
||||||
public:
|
public:
|
||||||
HashRevokeManager();
|
HashRevokeManager();
|
||||||
@@ -38,7 +67,7 @@ protected:
|
|||||||
status_t _ForceInsert(uint32 block, uint32 commitID);
|
status_t _ForceInsert(uint32 block, uint32 commitID);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
hash_table* fHash;
|
RevokeTable* fHash;
|
||||||
|
|
||||||
const int kInitialHashSize;
|
const int kInitialHashSize;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user