diff options
author | Max <mparisi@stevens.edu> | 2020-09-15 17:13:00 -0400 |
---|---|---|
committer | Max <mparisi@stevens.edu> | 2020-09-15 17:13:00 -0400 |
commit | 67fd727a3c293215c644bb690bad1db0df67046f (patch) | |
tree | 21720e999d6630c04c6d971906b56340075b2931 /src | |
parent | 7000f90b2f33dbc2325b6da49c7e3cfc5510e845 (diff) |
TableLookup, TableMapSafe, TableMapSafe2. Added darray.h header
Diffstat (limited to 'src')
-rw-r--r-- | src/hashtable.c | 83 |
1 files changed, 39 insertions, 44 deletions
diff --git a/src/hashtable.c b/src/hashtable.c index 5ba3a73..9d452e6 100644 --- a/src/hashtable.c +++ b/src/hashtable.c @@ -5,41 +5,25 @@ ==TableCount 8035aff0 80336948 88
==TableEnter 8035b078 803369d0 a8
==TableRemove 8035b120 80336a78 a4
-TableLookup 8035b1c4 80336b1c a0
-TableMapSafe 8035b264 80336bbc 6c
-TableMapSafe2 8035b2d0 80336c28 7c
+==TableLookup 8035b1c4 80336b1c a0
+==TableMapSafe 8035b264 80336bbc 6c
+==TableMapSafe2 8035b2d0 80336c28 7c
#endif
#include "types.h"
#include "hashtable.h"
-// TODO: move to darray.h
-typedef struct unkStruct2 {
-
-} unkStruct2;
-
-// size 0x14
-// hashtable
-typedef struct unkStruct {
- unkStruct2 **unk0;
- // (probably void *s)
- s32 unk4; // TODO: number of elements in unk0
- s32 unk8;
- s32 unkC; // TODO: callback to hashing function
- s32 unk10;
-} unkStruct;
-
-unkStruct *TableNew(s32 p1, s32 p2, s32 p3, s32 p4, s32 p5)
+unkStruct *TableNew(s32 p1, s32 p2, HashFunction p3, s32 p4, s32 p5)
{
return TableNew2(p1, p2, 4, p3, p4, p5);
}
-unkStruct *TableNew2(s32 p1, s32 p2, s32 p3, s32 p4, s32 p5, s32 p6)
+unkStruct *TableNew2(s32 p1, s32 p2, s32 p3, HashFunction p4, s32 p5, s32 p6)
{
- unkStruct *r30 = gsimalloc(sizeof(unkStruct));
- r30->unk0 = gsimalloc(p2 * sizeof(void *));
+ unkStruct *r30 = (unkStruct *)gsimalloc(sizeof(unkStruct));
+ r30->unk0 = (unkStruct2 **)gsimalloc(p2 * sizeof(unkStruct2 *));
for (s32 i = 0; i < p2; i++) {
- r30->unk0[i] = ArrayNew(p1, p3, p6);
+ r30->unk0[i] = (unkStruct2 *)ArrayNew(p1, p3, p6);
}
r30->unk4 = p2;
r30->unk8 = p6;
@@ -62,7 +46,7 @@ void TableFree(unkStruct *p1) s32 TableCount(unkStruct *p1)
{
if (!p1)
- return NULL;
+ return 0;
s32 totalSize = 0;
for (s32 i = 0; i < p1->unk4; i++) {
totalSize += ArrayLength(p1->unk0[i]);
@@ -71,7 +55,7 @@ s32 TableCount(unkStruct *p1) }
// TODO: p2 is element to be added
-void TableEnter(unkStruct *p1, p2)
+void TableEnter(unkStruct *p1, void *p2)
{
if (p1) {
s32 i = p1->unkC(p2, p1->unk4); // r31
@@ -84,7 +68,7 @@ void TableEnter(unkStruct *p1, p2) }
}
-BOOL TableRemove(unkStruct *p1, p2)
+BOOL TableRemove(unkStruct *p1, void *p2)
{
if (!p1)
return FALSE;
@@ -98,22 +82,33 @@ BOOL TableRemove(unkStruct *p1, p2) }
}
+// TODO: array seems to be generic. Confirm that void* is the
+// correct return type
+void *TableLookup(unkStruct *p1, void *p2)
+{
+ if (!p1)
+ return NULL;
+ s32 i = p1->unkC(p2, p1->unk4);
+ s32 result = ArraySearch(p1->unk0[i], p2, p1->unk10, 0, 0);
+ if (result == -1) {
+ return NULL;
+ } else {
+ return ArrayNth(p1->unk0[i], result);
+ }
+}
+void TableMapSafe(unkStruct *p1, s32 p2, s32 p3)
+{
+ for (s32 i = 0; i < p1->unk4; i++) {
+ ArrayMapBackwards(p1->unk0[i], p2, p3);
+ }
+}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+void TableMapSafe2(unkStruct *p1, s32 p2, s32 p3)
+{
+ for (s32 i = 0; i < p1->unk4; i++) {
+ if (ArrayMapBackwards2(p1->unk0[i], p2, p3)) {
+ break;
+ }
+ }
+}
|