8000 evictEntry added to the hash table · dlhoang/postgres@a8634c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit a8634c1

Browse files
nplewtonnplewton
nplewton
authored and
nplewton
committed
evictEntry added to the hash table
1 parent d1a7086 commit a8634c1

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/backend/storage/buffer/random.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,30 @@ void addEntry(uint64_t hashIndex, pageEntry *entry) {
4545
}
4646
}
4747

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+
4872
int main() {
4973
createHashTable();
5074

@@ -64,6 +88,10 @@ int main() {
6488
addEntry(hashIndex, copy);
6589

6690

91+
printTable();
92+
93+
printf("This is the returnAddress: %llu\n", evictEntry());
94+
6795
printTable();
6896

6997
return 0;

src/backend/storage/buffer/random.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdio.h>
55
#include <stdint.h>
66
#include <stdlib.h>
7+
#include <time.h>
78

89
#define HASHTABLE_SIZE 100
910

0 commit comments

Comments
 (0)
0