File tree 2 files changed +29
-0
lines changed
src/backend/storage/buffer 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,30 @@ void addEntry(uint64_t hashIndex, pageEntry *entry) {
45
45
}
46
46
}
47
47
48
+ uint64_t evictEntry () {
49
+ pageEntry * cur ;
50
+ pageEntry * prev = NULL ;
51
+ uint64_t returnAddress ;
52
+
53
+ srand (time (NULL ));
54
+ int randomIndex = rand () % hashTable -> capacity ;
55
+ while ((hashTable -> entries )[randomIndex ] == NULL ) {
56
+ randomIndex = rand () % hashTable -> capacity ;
57
+ }
58
+ printf ("This is r: %d\n" , randomIndex );
59
+
60
+ cur = hashTable -> entries [randomIndex ];
61
+ while (cur -> next != NULL ) {
62
+ prev = cur ;
63
+ cur = cur -> next ;
64
+ }
65
+ returnAddress = cur -> pageAddress ;
66
+ prev -> next = NULL ;
67
+ free (cur );
68
+
69
+ return returnAddress ;
70
+ }
71
+
48
72
int main () {
49
73
createHashTable ();
50
74
@@ -64,6 +88,10 @@ int main() {
64
88
addEntry (hashIndex , copy );
65
89
66
90
91
+ printTable ();
92
+
93
+ printf ("This is the returnAddress: %llu\n" , evictEntry ());
94
+
67
95
printTable ();
68
96
69
97
return 0 ;
Original file line number Diff line number Diff line change 4
4
#include <stdio.h>
5
5
#include <stdint.h>
6
6
#include <stdlib.h>
7
+ #include <time.h>
7
8
8
9
#define HASHTABLE_SIZE 100
9
10
You can’t perform that action at this time.
0 commit comments