xfs: make common lower bound function for calculating index of Hash
Change-Id: I5e902031b0e2a1051a7f96ab94dca0dba0ca9112 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5698 Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org> Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
This commit is contained in:
parent
88131dc314
commit
40b5272d86
@ -733,24 +733,10 @@ TreeDirectory::Lookup(const char* name, size_t length, xfs_ino_t* ino)
|
||||
int numberOfLeafEntries = leafHeader->Count();
|
||||
TRACE("numberOfLeafEntries:(%" B_PRId32 ")\n", numberOfLeafEntries);
|
||||
int left = 0;
|
||||
int mid;
|
||||
int right = numberOfLeafEntries - 1;
|
||||
|
||||
// Trying to find the lowerbound of hashValueOfRequest
|
||||
// This is slightly different from bsearch(), as we want the first
|
||||
// instance of hashValueOfRequest and not any instance.
|
||||
while (left < right) {
|
||||
mid = (left + right) / 2;
|
||||
uint32 hashval = B_BENDIAN_TO_HOST_INT32(leafEntry[mid].hashval);
|
||||
if (hashval >= hashValueOfRequest) {
|
||||
right = mid;
|
||||
continue;
|
||||
}
|
||||
if (hashval < hashValueOfRequest) {
|
||||
left = mid + 1;
|
||||
}
|
||||
}
|
||||
TRACE("left:(%" B_PRId32 "), right:(%" B_PRId32 ")\n", left, right);
|
||||
hashLowerBound<ExtentLeafEntry>(leafEntry, left, right, hashValueOfRequest);
|
||||
|
||||
uint32 nextLeaf = leafHeader->Forw();
|
||||
uint32 lastHashVal = B_BENDIAN_TO_HOST_INT32(
|
||||
leafEntry[numberOfLeafEntries - 1].hashval);
|
||||
|
@ -215,26 +215,9 @@ Extent::Lookup(const char* name, size_t length, xfs_ino_t* ino)
|
||||
|
||||
int numberOfLeafEntries = B_BENDIAN_TO_HOST_INT32(blockTail->count);
|
||||
int left = 0;
|
||||
int mid;
|
||||
int right = numberOfLeafEntries - 1;
|
||||
|
||||
/*
|
||||
* Trying to find the lowerbound of hashValueOfRequest
|
||||
* This is slightly different from bsearch(), as we want the first
|
||||
* instance of hashValueOfRequest and not any instance.
|
||||
*/
|
||||
while (left < right) {
|
||||
mid = (left+right)/2;
|
||||
uint32 hashval = B_BENDIAN_TO_HOST_INT32(leafEntry[mid].hashval);
|
||||
if (hashval >= hashValueOfRequest) {
|
||||
right = mid;
|
||||
continue;
|
||||
}
|
||||
if (hashval < hashValueOfRequest) {
|
||||
left = mid+1;
|
||||
}
|
||||
}
|
||||
TRACE("left:(%" B_PRId32 "), right:(%" B_PRId32 ")\n", left, right);
|
||||
hashLowerBound<ExtentLeafEntry>(leafEntry, left, right, hashValueOfRequest);
|
||||
|
||||
while (B_BENDIAN_TO_HOST_INT32(leafEntry[left].hashval)
|
||||
== hashValueOfRequest) {
|
||||
|
@ -144,10 +144,6 @@ struct ExtentMapEntry {
|
||||
};
|
||||
|
||||
|
||||
uint32
|
||||
hashfunction(const char* name, int length);
|
||||
|
||||
|
||||
struct xfs_timestamp_t {
|
||||
int32 t_sec;
|
||||
int32 t_nsec;
|
||||
@ -442,4 +438,32 @@ private:
|
||||
ExtentMapEntry* fExtents;
|
||||
};
|
||||
|
||||
|
||||
uint32 hashfunction(const char* name, int length);
|
||||
|
||||
|
||||
// A common function to return given hash lowerbound
|
||||
template<class T> void
|
||||
hashLowerBound(T* entry, int& left, int& right, uint32 hashValueOfRequest)
|
||||
{
|
||||
int mid;
|
||||
|
||||
/*
|
||||
* Trying to find the lowerbound of hashValueOfRequest
|
||||
* This is slightly different from bsearch(), as we want the first
|
||||
* instance of hashValueOfRequest and not any instance.
|
||||
*/
|
||||
while (left < right) {
|
||||
mid = (left + right) / 2;
|
||||
uint32 hashval = B_BENDIAN_TO_HOST_INT32(entry[mid].hashval);
|
||||
if (hashval >= hashValueOfRequest) {
|
||||
right = mid;
|
||||
continue;
|
||||
}
|
||||
if (hashval < hashValueOfRequest)
|
||||
left = mid+1;
|
||||
}
|
||||
TRACE("left:(%" B_PRId32 "), right:(%" B_PRId32 ")\n", left, right);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -286,24 +286,11 @@ LeafAttribute::Lookup(const char* name, size_t* nameLength)
|
||||
|
||||
int numberOfLeafEntries = header->Count();
|
||||
int left = 0;
|
||||
int mid;
|
||||
int right = numberOfLeafEntries - 1;
|
||||
|
||||
delete header;
|
||||
|
||||
// LowerBound
|
||||
while (left < right) {
|
||||
mid = (left + right) / 2;
|
||||
uint32 hashval = B_BENDIAN_TO_HOST_INT32(entry[mid].hashval);
|
||||
if (hashval >= hashValueOfRequest) {
|
||||
right = mid;
|
||||
continue;
|
||||
}
|
||||
if (hashval < hashValueOfRequest) {
|
||||
left = mid+1;
|
||||
}
|
||||
}
|
||||
TRACE("left:(%" B_PRId32 "), right:(%" B_PRId32 ")\n", left, right);
|
||||
hashLowerBound<AttrLeafEntry>(entry, left, right, hashValueOfRequest);
|
||||
|
||||
while (B_BENDIAN_TO_HOST_INT32(entry[left].hashval) == hashValueOfRequest) {
|
||||
|
||||
|
@ -342,27 +342,10 @@ LeafDirectory::Lookup(const char* name, size_t length, xfs_ino_t* ino)
|
||||
int numberOfLeafEntries = leafHeader->Count();
|
||||
TRACE("numberOfLeafEntries:(%" B_PRId32 ")\n", numberOfLeafEntries);
|
||||
int left = 0;
|
||||
int mid;
|
||||
int right = numberOfLeafEntries - 1;
|
||||
Volume* volume = fInode->GetVolume();
|
||||
|
||||
/*
|
||||
* Trying to find the lowerbound of hashValueOfRequest
|
||||
* This is slightly different from bsearch(), as we want the first
|
||||
* instance of hashValueOfRequest and not any instance.
|
||||
*/
|
||||
while (left < right) {
|
||||
mid = (left+right)/2;
|
||||
uint32 hashval = B_BENDIAN_TO_HOST_INT32(leafEntry[mid].hashval);
|
||||
if (hashval >= hashValueOfRequest) {
|
||||
right = mid;
|
||||
continue;
|
||||
}
|
||||
if (hashval < hashValueOfRequest) {
|
||||
left = mid+1;
|
||||
}
|
||||
}
|
||||
TRACE("left:(%" B_PRId32 "), right:(%" B_PRId32 ")\n", left, right);
|
||||
hashLowerBound<ExtentLeafEntry>(leafEntry, left, right, hashValueOfRequest);
|
||||
|
||||
while (B_BENDIAN_TO_HOST_INT32(leafEntry[left].hashval)
|
||||
== hashValueOfRequest) {
|
||||
|
@ -399,27 +399,10 @@ NodeDirectory::Lookup(const char* name, size_t length, xfs_ino_t* ino)
|
||||
int numberOfLeafEntries = leafHeader->Count();
|
||||
TRACE("numberOfLeafEntries:(%" B_PRId32 ")\n", numberOfLeafEntries);
|
||||
int left = 0;
|
||||
int mid;
|
||||
int right = numberOfLeafEntries - 1;
|
||||
Volume* volume = fInode->GetVolume();
|
||||
|
||||
/*
|
||||
* Trying to find the lowerbound of hashValueOfRequest
|
||||
* This is slightly different from bsearch(), as we want the first
|
||||
* instance of hashValueOfRequest and not any instance.
|
||||
*/
|
||||
while (left < right) {
|
||||
mid = (left + right) / 2;
|
||||
uint32 hashval = B_BENDIAN_TO_HOST_INT32(leafEntry[mid].hashval);
|
||||
if (hashval >= hashValueOfRequest) {
|
||||
right = mid;
|
||||
continue;
|
||||
}
|
||||
if (hashval < hashValueOfRequest) {
|
||||
left = mid + 1;
|
||||
}
|
||||
}
|
||||
TRACE("left:(%" B_PRId32 "), right:(%" B_PRId32 ")\n", left, right);
|
||||
hashLowerBound<ExtentLeafEntry>(leafEntry, left, right, hashValueOfRequest);
|
||||
|
||||
while (B_BENDIAN_TO_HOST_INT32(leafEntry[left].hashval)
|
||||
== hashValueOfRequest) {
|
||||
@ -672,4 +655,4 @@ SizeOfNodeHeader(Inode* inode)
|
||||
return sizeof(NodeHeaderV4) - XFS_NODE_V4_VPTR_OFF;
|
||||
else
|
||||
return sizeof(NodeHeaderV5) - XFS_NODE_V5_VPTR_OFF;
|
||||
}
|
||||
}
|
@ -326,27 +326,13 @@ NodeAttribute::Lookup(const char* name, size_t* nameLength)
|
||||
|
||||
int TotalNodeEntries = node->Count();
|
||||
int left = 0;
|
||||
int mid;
|
||||
int right = TotalNodeEntries - 1;
|
||||
|
||||
delete node;
|
||||
|
||||
// LowerBound
|
||||
while (left < right) {
|
||||
mid = (left + right) / 2;
|
||||
uint32 hashval = B_BENDIAN_TO_HOST_INT32(nodeEntry[mid].hashval);
|
||||
if (hashval >= hashValueOfRequest) {
|
||||
right = mid;
|
||||
continue;
|
||||
}
|
||||
if (hashval < hashValueOfRequest) {
|
||||
left = mid + 1;
|
||||
}
|
||||
}
|
||||
TRACE("left:(%" B_PRId32 "), right:(%" B_PRId32 ")\n", left, right);
|
||||
hashLowerBound<NodeEntry>(nodeEntry, left, right, hashValueOfRequest);
|
||||
|
||||
// We found our potential leaf block, now read leaf buffer
|
||||
|
||||
// First see the leaf block from NodeEntry and logical block offset
|
||||
uint32 logicalBlock = B_BENDIAN_TO_HOST_INT32(nodeEntry[left].before);
|
||||
// Now calculate File system Block of This logical block
|
||||
@ -362,19 +348,7 @@ NodeAttribute::Lookup(const char* name, size_t* nameLength)
|
||||
|
||||
delete header;
|
||||
|
||||
// LowerBound
|
||||
while (left < right) {
|
||||
mid = (left + right) / 2;
|
||||
uint32 hashval = B_BENDIAN_TO_HOST_INT32(entry[mid].hashval);
|
||||
if (hashval >= hashValueOfRequest) {
|
||||
right = mid;
|
||||
continue;
|
||||
}
|
||||
if (hashval < hashValueOfRequest) {
|
||||
left = mid + 1;
|
||||
}
|
||||
}
|
||||
TRACE("left:(%" B_PRId32 "), right:(%" B_PRId32 ")\n", left, right);
|
||||
hashLowerBound<AttrLeafEntry>(entry, left, right, hashValueOfRequest);
|
||||
|
||||
while (B_BENDIAN_TO_HOST_INT32(entry[left].hashval)
|
||||
== hashValueOfRequest) {
|
||||
|
Loading…
Reference in New Issue
Block a user