From 09fb7d4bbce5fe8c5c1142a9744646e5de7dd1d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 16 Sep 2003 02:33:48 +0000 Subject: [PATCH] Implemented hash functions for DirectoryBlock. Added HashIterator::InitCheck() method (as the allocation of the buffer might fail). Added a HashIterator::Goto() method to jump to the specified index in the hash (handy for hash lookup). git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4707 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../file_systems/amiga_ffs/amiga_ffs.cpp | 41 +++++++++++++++++-- .../loader/file_systems/amiga_ffs/amiga_ffs.h | 5 ++- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.cpp b/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.cpp index 501ae8f8c5..2eb59db91c 100644 --- a/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.cpp +++ b/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.cpp @@ -73,10 +73,30 @@ BaseBlock::ValidateCheckSum() const // #pragma mark - -int32 -DirectoryBlock::HashIndexFor(const char *name) +char +DirectoryBlock::ToUpperChar(int32 type, char c) const { - return 0; + // Taken from Ralph Babel's "The Amiga Guru Book" (1993), section 15.3.4.3 + + if (type == DT_AMIGA_OFS || type == DT_AMIGA_FFS) + return c >= 'a' && c <= 'z' ? c + ('A' - 'a') : c; + + return (c >= '\340' && c <= '\376' && c != '\367') + || (c >= 'a' && c <= 'z') ? c + ('A' - 'a') : c; +} + + +int32 +DirectoryBlock::HashIndexFor(int32 type, const char *name) const +{ + int32 hash = strlen(name); + + while (name[0]) { + hash = (hash * 13 + ToUpperChar(type, name[0])) & 0x7ff; + name++; + } + + return hash % HashSize(); } @@ -131,6 +151,21 @@ HashIterator::~HashIterator() } +status_t +HashIterator::InitCheck() +{ + return fData != NULL ? B_OK : B_NO_MEMORY; +} + + +void +HashIterator::Goto(int32 index) +{ + fCurrent = index; + fBlock = fDirectory.HashValueAt(index); +} + + NodeBlock * HashIterator::GetNext(int32 &block) { diff --git a/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.h b/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.h index 44b447247c..8858fb4e4c 100644 --- a/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.h +++ b/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.h @@ -87,7 +87,8 @@ class DirectoryBlock : public NodeBlock { DirectoryBlock(int32 blockSize) : NodeBlock(blockSize) {} DirectoryBlock(void *data, int32 blockSize) : NodeBlock(data, blockSize) {} - int32 HashIndexFor(const char *name); + char ToUpperChar(int32 type, char c) const; + int32 HashIndexFor(int32 type, const char *name) const; int32 HashValueAt(int32 index) const; int32 NextHashValue(int32 &index) const; @@ -143,6 +144,8 @@ class HashIterator { HashIterator(int32 device, DirectoryBlock &node); ~HashIterator(); + status_t InitCheck(); + void Goto(int32 index); NodeBlock *GetNext(int32 &block); void Rewind();