Commit 35b5c6f9 authored by Andreas Schmidt's avatar Andreas Schmidt

BPTree now supports larger keys. Extract dataPacketStore.

parent 390d2240
Pipeline #102 failed with stage
...@@ -107,7 +107,7 @@ cdef extern from "prrt/socket.h": ...@@ -107,7 +107,7 @@ cdef extern from "prrt/socket.h":
BPTreeNode* dataStore BPTreeNode* dataStore
BPTreeNode* blockStore PrrtRepairBlockStore* repairBlockStore
PrrtForwardPacketTable* forwardPacketTable PrrtForwardPacketTable* forwardPacketTable
......
...@@ -12,6 +12,6 @@ add_library(PRRT ../defines.h ...@@ -12,6 +12,6 @@ add_library(PRRT ../defines.h
stores/lossGatherer.c stores/lossGatherer.h stores/lossGatherer.c stores/lossGatherer.h
processes/dataReceiver.c processes/dataReceiver.h processes/dataReceiver.c processes/dataReceiver.h
processes/feedbackReceiver.c processes/feedbackReceiver.h processes/feedbackReceiver.c processes/feedbackReceiver.h
processes/dataTransmitter.c processes/dataTransmitter.h processes/cleaner.c processes/cleaner.h stores/repairBlockStore.c stores/repairBlockStore.h stores/packetTimeoutTable.c stores/packetTimeoutTable.h) processes/dataTransmitter.c processes/dataTransmitter.h processes/cleaner.c processes/cleaner.h stores/repairBlockStore.c stores/repairBlockStore.h stores/packetTimeoutTable.c stores/packetTimeoutTable.h stores/dataPacketStore.c stores/dataPacketStore.h)
set_property(TARGET PRRT PROPERTY C_STANDARD 99) set_property(TARGET PRRT PROPERTY C_STANDARD 99)
\ No newline at end of file
...@@ -12,13 +12,14 @@ ...@@ -12,13 +12,14 @@
void retrieve_data_blocks(PrrtSocket *sock_ptr, prrtSequenceNumber_t base_seqno, uint8_t k, const PrrtBlock *block) void retrieve_data_blocks(PrrtSocket *sock_ptr, prrtSequenceNumber_t base_seqno, uint8_t k, const PrrtBlock *block)
{ {
List *res = List_create(); List *res = List_create();
BPTree_get_range(sock_ptr->dataStore, res, base_seqno, base_seqno + k - 1);
PrrtDataPacketStore_remove_range(sock_ptr->dataPacketStore, res, base_seqno, (prrtSequenceNumber_t) (base_seqno + k - 1));
LIST_FOREACH(res, first, next, cur) { LIST_FOREACH(res, first, next, cur) {
PrrtPacket *packetPtr = cur->value; PrrtPacket *packetPtr = cur->value;
check(PrrtBlock_insert_data_packet((PrrtBlock *) block, packetPtr), "Insert failed!") check(PrrtBlock_insert_data_packet((PrrtBlock *) block, packetPtr), "Insert failed!")
sock_ptr->dataStore = BPTree_delete(sock_ptr->dataStore, packetPtr->sequenceNumber);
} }
error: error:
List_destroy(res); List_destroy(res);
} }
...@@ -122,10 +123,7 @@ void handle_data_packet(PrrtSocket *sock_ptr, PrrtPacket *packet, struct sockadd ...@@ -122,10 +123,7 @@ void handle_data_packet(PrrtSocket *sock_ptr, PrrtPacket *packet, struct sockadd
check(PrrtBlock_insert_data_packet(block, reference), "Inserting failed"); check(PrrtBlock_insert_data_packet(block, reference), "Inserting failed");
decode_block(sock_ptr, block); decode_block(sock_ptr, block);
} else { } else {
// Check for duplicate data packet. if(PrrtDataStore_insert(sock_ptr->dataPacketStore, reference) == false) {
if(BPTree_get(sock_ptr->dataStore, packet->sequenceNumber) == NULL) {
sock_ptr->dataStore = BPTree_insert(sock_ptr->dataStore, packet->sequenceNumber, reference);
} else {
PrrtPacket_destroy(reference); PrrtPacket_destroy(reference);
} }
} }
...@@ -207,8 +205,6 @@ void *receive_data_loop(void *ptr) ...@@ -207,8 +205,6 @@ void *receive_data_loop(void *ptr)
} }
} }
// TODO: occasionally clean up dataStore !!!
error: error:
PNOTIMPLEMENTED("SHOULD IMPLEMENT ERROR HANDLER HERE"); PNOTIMPLEMENTED("SHOULD IMPLEMENT ERROR HANDLER HERE");
} }
...@@ -38,7 +38,7 @@ PrrtSocket *PrrtSocket_create(const bool is_sender) ...@@ -38,7 +38,7 @@ PrrtSocket *PrrtSocket_create(const bool is_sender)
sock_ptr->packetTimeoutTable = PrrtPacketTimeoutTable_create(); sock_ptr->packetTimeoutTable = PrrtPacketTimeoutTable_create();
sock_ptr->dataStore = NULL; sock_ptr->dataPacketStore = PrrtDataPacketStore_create();
check(sock_ptr->dataSocketFd = socket(AF_INET, SOCK_DGRAM, 0), "Cannot create data socket.") check(sock_ptr->dataSocketFd = socket(AF_INET, SOCK_DGRAM, 0), "Cannot create data socket.")
check(sock_ptr->feedbackSocketFd = socket(AF_INET, SOCK_DGRAM, 0), "Cannot create feedback socket."); check(sock_ptr->feedbackSocketFd = socket(AF_INET, SOCK_DGRAM, 0), "Cannot create feedback socket.");
...@@ -215,17 +215,9 @@ int PrrtSocket_close(PrrtSocket *sock_ptr) { ...@@ -215,17 +215,9 @@ int PrrtSocket_close(PrrtSocket *sock_ptr) {
check(pthread_mutex_unlock(&sock_ptr->closingMutex) == 0, "Unlock failed."); check(pthread_mutex_unlock(&sock_ptr->closingMutex) == 0, "Unlock failed.");
} }
if (sock_ptr->dataStore != NULL) { if(sock_ptr->dataPacketStore != NULL) {
List *dataList = List_create(); check(PrrtDataPacketStore_destroy(sock_ptr->dataPacketStore), "Destroy failed.");
BPTree_get_range(sock_ptr->dataStore, dataList, 0, SEQNO_SPACE - 1); sock_ptr->dataPacketStore = NULL;
while (List_count(dataList) > 0) {
PrrtPacket *packet = List_shift(dataList);
PrrtPacket_destroy(packet);
}
List_destroy(dataList);
sock_ptr->dataStore = BPTree_destroy(sock_ptr->dataStore);
} }
if(sock_ptr->repairBlockStore != NULL) { if(sock_ptr->repairBlockStore != NULL) {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "../util/bptree.h" #include "../util/bptree.h"
#include "channelStateInformation.h" #include "channelStateInformation.h"
#include "applicationConstraints.h" #include "applicationConstraints.h"
#include "stores/dataPacketStore.h"
#include "stores/packetTimeoutTable.h" #include "stores/packetTimeoutTable.h"
#include "stores/repairBlockStore.h" #include "stores/repairBlockStore.h"
#include "clock.h" #include "clock.h"
...@@ -35,10 +36,7 @@ typedef struct prrtSocket { ...@@ -35,10 +36,7 @@ typedef struct prrtSocket {
pthread_t cleanupThread; pthread_t cleanupThread;
BPTreeNode* dataStore;
PrrtPacketTimeoutTable* packetTimeoutTable; PrrtPacketTimeoutTable* packetTimeoutTable;
PrrtDataPacketStore* dataPacketStore; PrrtDataPacketStore* dataPacketStore;
PrrtRepairBlockStore* repairBlockStore; PrrtRepairBlockStore* repairBlockStore;
......
#include <stdlib.h>
#include <pthread.h>
#include "../../util/common.h"
#include "../../util/bptree.h"
#include "../../util/dbg.h"
#include "../packet.h"
#include "dataPacketStore.h"
PrrtDataPacketStore *PrrtDataPacketStore_create(void)
{
PrrtDataPacketStore* store = calloc(1, sizeof(PrrtDataPacketStore));
check_mem(store);
check(pthread_mutex_init(&store->lock, NULL) == EXIT_SUCCESS, "Init mutex failed.")
return store;
error:
PERROR("Out of memory%s.","");
return NULL;
}
uint32_t PrrtDataPacketStore_size(PrrtDataPacketStore *store)
{
check(pthread_mutex_lock(&store->lock) == EXIT_SUCCESS, "Lock failed.");
uint32_t res = BPTree_size(store->dataStore);
check(pthread_mutex_unlock(&store->lock) == EXIT_SUCCESS, "Unlock failed.");
return res;
error:
PERROR("Getting size failed%s.", "");
return 0;
}
bool PrrtDataPacketStore_destroy(PrrtDataPacketStore *store)
{
List *dataList = List_create();
BPTree_get_range(store->dataStore, dataList, 0, SEQNO_SPACE - 1);
while(List_count(dataList) > 0) {
PrrtPacket *packet = List_shift(dataList);
PrrtPacket_destroy(packet);
}
List_destroy(dataList);
check(pthread_mutex_destroy(&store->lock) == EXIT_SUCCESS, "Destroy failed.");
store->dataStore = BPTree_destroy(store->dataStore);
free(store);
return true;
error:
PERROR("Could not destroy%s.","");
return false;
}
void PrrtDataPacketStore_remove_range(PrrtDataPacketStore *store, List *res, prrtSequenceNumber_t start, prrtSequenceNumber_t stop)
{
// TODO: handle if start > stop
BPTree_get_range(store->dataStore, res, start, stop);
LIST_FOREACH(res, first, next, current) {
PrrtPacket *packet = current->value;
store->dataStore = BPTree_delete(store->dataStore, packet->sequenceNumber);
}
}
bool PrrtDataStore_insert(PrrtDataPacketStore *store, PrrtPacket *packet)
{
if(BPTree_get(store->dataStore, packet->sequenceNumber) == NULL) {
store->dataStore = BPTree_insert(store->dataStore, packet->sequenceNumber, packet);
return true;
}
return false;
}
#include <stdint.h>
#include <stdbool.h>
#include <bits/pthreadtypes.h>
#ifndef PRRT_DATAPACKETSTORE_H
#define PRRT_DATAPACKETSTORE_H
typedef struct prrtDataPacketStore {
pthread_mutex_t lock;
BPTreeNode* dataStore;
} PrrtDataPacketStore;
PrrtDataPacketStore* PrrtDataPacketStore_create(void);
uint32_t PrrtDataPacketStore_size(PrrtDataPacketStore* store);
void PrrtDataPacketStore_remove_range(PrrtDataPacketStore *store, List *res, prrtSequenceNumber_t start, prrtSequenceNumber_t stop);
bool PrrtDataPacketStore_destroy(PrrtDataPacketStore* store);
bool PrrtDataStore_insert(PrrtDataPacketStore *store, PrrtPacket *packet);
#endif //PRRT_DATAPACKETSTORE_H
...@@ -10,7 +10,7 @@ PrrtPacketTimeoutTable *PrrtPacketTimeoutTable_create(void) ...@@ -10,7 +10,7 @@ PrrtPacketTimeoutTable *PrrtPacketTimeoutTable_create(void)
table->packetList = NULL; table->packetList = NULL;
pthread_mutex_init(&table->lock, NULL); check(pthread_mutex_init(&table->lock, NULL) == EXIT_SUCCESS, "Init mutex failed.");
return table; return table;
error: error:
......
...@@ -8,7 +8,7 @@ PrrtRepairBlockStore *PrrtRepairBlockStore_create(void) ...@@ -8,7 +8,7 @@ PrrtRepairBlockStore *PrrtRepairBlockStore_create(void)
PrrtRepairBlockStore *store = (PrrtRepairBlockStore *) calloc(1, sizeof(PrrtRepairBlockStore)); PrrtRepairBlockStore *store = (PrrtRepairBlockStore *) calloc(1, sizeof(PrrtRepairBlockStore));
check_mem(store); check_mem(store);
pthread_mutex_init(&store->lock, NULL); check(pthread_mutex_init(&store->lock, NULL) == EXIT_SUCCESS, "Init mutex failed.");
store->blockTree = NULL; store->blockTree = NULL;
return store; return store;
...@@ -86,7 +86,6 @@ bool PrrtRepairBlockStore_expire_block_range(PrrtRepairBlockStore *store, prrtSe ...@@ -86,7 +86,6 @@ bool PrrtRepairBlockStore_expire_block_range(PrrtRepairBlockStore *store, prrtSe
check(pthread_mutex_lock(&store->lock) == EXIT_SUCCESS, "Lock failed."); check(pthread_mutex_lock(&store->lock) == EXIT_SUCCESS, "Lock failed.");
while(start != stop) { while(start != stop) {
store->blockTree = BPTree_delete(store->blockTree, start); store->blockTree = BPTree_delete(store->blockTree, start);
debug("EXPIRE BLOCK: %d", start);
start++; start++;
} }
check(pthread_mutex_unlock(&store->lock) == EXIT_SUCCESS, "Unlock failed."); check(pthread_mutex_unlock(&store->lock) == EXIT_SUCCESS, "Unlock failed.");
......
...@@ -47,7 +47,6 @@ typedef struct { ...@@ -47,7 +47,6 @@ typedef struct {
void *value; void *value;
} BPTreeRecord; } BPTreeRecord;
// GLOBALS. // GLOBALS.
/* The order determines the maximum and minimum number of entries (keys and pointers) in any node. Every node has at /* The order determines the maximum and minimum number of entries (keys and pointers) in any node. Every node has at
...@@ -72,15 +71,15 @@ void enqueue(BPTreeNode *new_node); ...@@ -72,15 +71,15 @@ void enqueue(BPTreeNode *new_node);
BPTreeNode *dequeue(void); BPTreeNode *dequeue(void);
int path_to_root(BPTreeNode *root, BPTreeNode *child); BPTreeKey_t path_to_root(BPTreeNode *root, BPTreeNode *child);
int find_range(BPTreeNode *root, int key_start, int key_end, int returned_keys[], void *returned_pointers[]); BPTreeKey_t find_range(BPTreeNode *root, BPTreeKey_t key_start, BPTreeKey_t key_end, BPTreeKey_t *returned_keys, void **returned_pointers);
BPTreeNode *find_leaf(BPTreeNode *root, int key); BPTreeNode *find_leaf(BPTreeNode *root, BPTreeKey_t key);
BPTreeRecord *find(BPTreeNode *root, int key); BPTreeRecord *find(BPTreeNode *root, BPTreeKey_t key);
int cut(int length); BPTreeKey_t cut(BPTreeKey_t length);
// Insertion. // Insertion.
...@@ -90,36 +89,36 @@ BPTreeNode *make_node(void); ...@@ -90,36 +89,36 @@ BPTreeNode *make_node(void);
BPTreeNode *make_leaf(void); BPTreeNode *make_leaf(void);
int get_left_index(BPTreeNode *parent, BPTreeNode *left); BPTreeKey_t get_left_index(BPTreeNode *parent, BPTreeNode *left);
BPTreeNode *insert_into_leaf(BPTreeNode *leaf, int key, BPTreeRecord *pointer); BPTreeNode *insert_into_leaf(BPTreeNode *leaf, BPTreeKey_t key, BPTreeRecord *pointer);
BPTreeNode *insert_into_leaf_after_splitting(BPTreeNode *root, BPTreeNode *leaf, int key, BPTreeRecord *pointer); BPTreeNode *insert_into_leaf_after_splitting(BPTreeNode *root, BPTreeNode *leaf, BPTreeKey_t key, BPTreeRecord *pointer);
BPTreeNode *insert_into_node(BPTreeNode *root, BPTreeNode *parent, BPTreeNode *insert_into_node(BPTreeNode *root, BPTreeNode *parent,
int left_index, int key, BPTreeNode *right); BPTreeKey_t left_index, BPTreeKey_t key, BPTreeNode *right);
BPTreeNode *insert_into_node_after_splitting(BPTreeNode *root, BPTreeNode *parent, int left_index, BPTreeNode *insert_into_node_after_splitting(BPTreeNode *root, BPTreeNode *parent, BPTreeKey_t left_index,
int key, BPTreeNode *right); BPTreeKey_t key, BPTreeNode *right);
BPTreeNode *insert_into_parent(BPTreeNode *root, BPTreeNode *left, int key, BPTreeNode *right); BPTreeNode *insert_into_parent(BPTreeNode *root, BPTreeNode *left, BPTreeKey_t key, BPTreeNode *right);
BPTreeNode *insert_into_new_root(BPTreeNode *left, int key, BPTreeNode *right); BPTreeNode *insert_into_new_root(BPTreeNode *left, BPTreeKey_t key, BPTreeNode *right);
BPTreeNode *start_new_tree(int key, BPTreeRecord *pointer); BPTreeNode *start_new_tree(BPTreeKey_t key, BPTreeRecord *pointer);
// Deletion. // Deletion.
int get_neighbor_index(BPTreeNode *n); BPTreeKey_t get_neighbor_index(BPTreeNode *n);
BPTreeNode *adjust_root(BPTreeNode *root); BPTreeNode *adjust_root(BPTreeNode *root);
BPTreeNode *coalesce_nodes(BPTreeNode *root, BPTreeNode *n, BPTreeNode *neighbor, int neighbor_index, int k_prime); BPTreeNode *coalesce_nodes(BPTreeNode *root, BPTreeNode *n, BPTreeNode *neighbor, BPTreeKey_t neighbor_index, BPTreeKey_t k_prime);
BPTreeNode *redistribute_nodes(BPTreeNode *root, BPTreeNode *n, BPTreeNode *neighbor, int neighbor_index, BPTreeNode *redistribute_nodes(BPTreeNode *root, BPTreeNode *n, BPTreeNode *neighbor, BPTreeKey_t neighbor_index,
int k_prime_index, int k_prime); BPTreeKey_t k_prime_index, BPTreeKey_t k_prime);
BPTreeNode *delete_entry(BPTreeNode *root, BPTreeNode *n, int key, void *pointer); BPTreeNode *delete_entry(BPTreeNode *root, BPTreeNode *n, BPTreeKey_t key, void *pointer);
// FUNCTION DEFINITIONS. // FUNCTION DEFINITIONS.
...@@ -173,8 +172,8 @@ int BPTree_height(BPTreeNode *root) { ...@@ -173,8 +172,8 @@ int BPTree_height(BPTreeNode *root) {
/* Utility function to give the length in edges /* Utility function to give the length in edges
* of the path from any node to the root. * of the path from any node to the root.
*/ */
int path_to_root(BPTreeNode *root, BPTreeNode *child) { BPTreeKey_t path_to_root(BPTreeNode *root, BPTreeNode *child) {
int length = 0; BPTreeKey_t length = 0;
BPTreeNode *c = child; BPTreeNode *c = child;
while (c != root) { while (c != root) {
c = c->parent; c = c->parent;
...@@ -189,9 +188,9 @@ int path_to_root(BPTreeNode *root, BPTreeNode *child) { ...@@ -189,9 +188,9 @@ int path_to_root(BPTreeNode *root, BPTreeNode *child) {
*/ */
void BPTree_print(BPTreeNode *root) { void BPTree_print(BPTreeNode *root) {
BPTreeNode *n = NULL; BPTreeNode *n = NULL;
int i = 0; BPTreeKey_t i = 0;
int rank = 0; BPTreeKey_t rank = 0;
int new_rank = 0; BPTreeKey_t new_rank = 0;
if (root == NULL) { if (root == NULL) {
printf("Empty tree.\n"); printf("Empty tree.\n");
...@@ -209,7 +208,7 @@ void BPTree_print(BPTreeNode *root) { ...@@ -209,7 +208,7 @@ void BPTree_print(BPTreeNode *root) {
} }
} }
for (i = 0; i < n->num_keys; i++) { for (i = 0; i < n->num_keys; i++) {
printf("%d ", n->keys[i]); printf("%ld ", n->keys[i]);
} }
if (!n->is_leaf) if (!n->is_leaf)
for (i = 0; i <= n->num_keys; i++) for (i = 0; i <= n->num_keys; i++)
...@@ -224,8 +223,8 @@ void BPTree_print(BPTreeNode *root) { ...@@ -224,8 +223,8 @@ void BPTree_print(BPTreeNode *root) {
* returned_keys and returned_pointers, and returns the number of * returned_keys and returned_pointers, and returns the number of
* entries found. * entries found.
*/ */
int find_range(BPTreeNode *root, int key_start, int key_end, int returned_keys[], void *returned_pointers[]) { BPTreeKey_t find_range(BPTreeNode *root, BPTreeKey_t key_start, BPTreeKey_t key_end, BPTreeKey_t *returned_keys, void **returned_pointers) {
int i, num_found; BPTreeKey_t i, num_found;
num_found = 0; num_found = 0;
BPTreeNode *n = find_leaf(root, key_start); BPTreeNode *n = find_leaf(root, key_start);
if (n == NULL) return 0; if (n == NULL) return 0;
...@@ -246,7 +245,7 @@ int find_range(BPTreeNode *root, int key_start, int key_end, int returned_keys[] ...@@ -246,7 +245,7 @@ int find_range(BPTreeNode *root, int key_start, int key_end, int returned_keys[]
/* Traces the path from the root to a leaf, searching by key. Returns the leaf containing the given key. /* Traces the path from the root to a leaf, searching by key. Returns the leaf containing the given key.
*/ */
BPTreeNode *find_leaf(BPTreeNode *root, int key) { BPTreeNode *find_leaf(BPTreeNode *root, BPTreeKey_t key) {
int i = 0; int i = 0;
BPTreeNode *c = root; BPTreeNode *c = root;
if (c == NULL) { if (c == NULL) {
...@@ -266,7 +265,7 @@ BPTreeNode *find_leaf(BPTreeNode *root, int key) { ...@@ -266,7 +265,7 @@ BPTreeNode *find_leaf(BPTreeNode *root, int key) {
/* Finds and returns the BPTreeRecord to which a key refers. /* Finds and returns the BPTreeRecord to which a key refers.
*/ */
BPTreeRecord *find(BPTreeNode *root, int key) { BPTreeRecord *find(BPTreeNode *root, BPTreeKey_t key) {
int i = 0; int i = 0;
BPTreeNode *c = find_leaf(root, key); BPTreeNode *c = find_leaf(root, key);
if (c == NULL) return NULL; if (c == NULL) return NULL;
...@@ -280,7 +279,7 @@ BPTreeRecord *find(BPTreeNode *root, int key) { ...@@ -280,7 +279,7 @@ BPTreeRecord *find(BPTreeNode *root, int key) {
/* Finds the appropriate place to split a node that is too big into two. /* Finds the appropriate place to split a node that is too big into two.
*/ */
int cut(int length) { BPTreeKey_t cut(BPTreeKey_t length) {
if (length % 2 == 0) if (length % 2 == 0)
return length / 2; return length / 2;
else else
...@@ -314,7 +313,7 @@ BPTreeNode *make_node(void) { ...@@ -314,7 +313,7 @@ BPTreeNode *make_node(void) {
perror("Node creation."); perror("Node creation.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
new_node->keys = calloc((size_t) (order - 1), sizeof(int)); new_node->keys = calloc((size_t) (order - 1), sizeof(BPTreeKey_t));
if (new_node->keys == NULL) { if (new_node->keys == NULL) {
perror("New node keys array."); perror("New node keys array.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -345,9 +344,9 @@ BPTreeNode *make_leaf(void) { ...@@ -345,9 +344,9 @@ BPTreeNode *make_leaf(void) {
* to find the index of the parent's pointer to * to find the index of the parent's pointer to
* the node to the left of the key to be inserted. * the node to the left of the key to be inserted.
*/ */
int get_left_index(BPTreeNode *parent, BPTreeNode *left) { BPTreeKey_t get_left_index(BPTreeNode *parent, BPTreeNode *left) {
int left_index = 0; BPTreeKey_t left_index = 0;
while (left_index <= parent->num_keys && while (left_index <= parent->num_keys &&
parent->pointers[left_index] != left) parent->pointers[left_index] != left)
left_index++; left_index++;
...@@ -358,7 +357,7 @@ int get_left_index(BPTreeNode *parent, BPTreeNode *left) { ...@@ -358,7 +357,7 @@ int get_left_index(BPTreeNode *parent, BPTreeNode *left) {
* key into a leaf. * key into a leaf.
* Returns the altered leaf. * Returns the altered leaf.
*/ */
BPTreeNode *insert_into_leaf(BPTreeNode *leaf, int key, BPTreeRecord *pointer) { BPTreeNode *insert_into_leaf(BPTreeNode *leaf, BPTreeKey_t key, BPTreeRecord *pointer) {
int i, insertion_point; int i, insertion_point;
...@@ -382,16 +381,16 @@ BPTreeNode *insert_into_leaf(BPTreeNode *leaf, int key, BPTreeRecord *pointer) { ...@@ -382,16 +381,16 @@ BPTreeNode *insert_into_leaf(BPTreeNode *leaf, int key, BPTreeRecord *pointer) {
* the tree's order, causing the leaf to be split * the tree's order, causing the leaf to be split
* in half. * in half.
*/ */
BPTreeNode *insert_into_leaf_after_splitting(BPTreeNode *root, BPTreeNode *leaf, int key, BPTreeRecord *pointer) { BPTreeNode *insert_into_leaf_after_splitting(BPTreeNode *root, BPTreeNode *leaf, BPTreeKey_t key, BPTreeRecord *pointer) {
BPTreeNode *new_leaf; BPTreeNode *new_leaf;
int *temp_keys; BPTreeKey_t *temp_keys;
void **temp_pointers; void **temp_pointers;
int insertion_index, split, new_key, i, j; int insertion_index, split, new_key, i, j;
new_leaf = make_leaf(); new_leaf = make_leaf();
temp_keys = calloc((size_t) order, sizeof(int)); temp_keys = calloc((size_t) order, sizeof(BPTreeKey_t));
if (temp_keys == NULL) { if (temp_keys == NULL) {
perror("Temporary keys array."); perror("Temporary keys array.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -455,8 +454,8 @@ BPTreeNode *insert_into_leaf_after_splitting(BPTreeNode *root, BPTreeNode *leaf, ...@@ -455,8 +454,8 @@ BPTreeNode *insert_into_leaf_after_splitting(BPTreeNode *root, BPTreeNode *leaf,
* without violating the B+ tree properties. * without violating the B+ tree properties.
*/ */
BPTreeNode *insert_into_node(BPTreeNode *root, BPTreeNode *n, BPTreeNode *insert_into_node(BPTreeNode *root, BPTreeNode *n,
int left_index, int key, BPTreeNode *right) { BPTreeKey_t left_index, BPTreeKey_t key, BPTreeNode *right) {
int i; BPTreeKey_t i;
for (i = n->num_keys; i > left_index; i--) { for (i = n->num_keys; i > left_index; i--) {
n->pointers[i + 1] = n->pointers[i]; n->pointers[i + 1] = n->pointers[i];
...@@ -473,12 +472,12 @@ BPTreeNode *insert_into_node(BPTreeNode *root, BPTreeNode *n, ...@@ -473,12 +472,12 @@ BPTreeNode *insert_into_node(BPTreeNode *root, BPTreeNode *n,
* into a node, causing the node's size to exceed * into a node, causing the node's size to exceed
* the order, and causing the node to split into two. * the order, and causing the node to split into two.
*/ */
BPTreeNode *insert_into_node_after_splitting(BPTreeNode *root, BPTreeNode *old_node, int left_index, BPTreeNode *insert_into_node_after_splitting(BPTreeNode *root, BPTreeNode *old_node, BPTreeKey_t left_index,
int key, BPTreeNode *right) { BPTreeKey_t key, BPTreeNode *right) {
int i, j, split, k_prime; BPTreeKey_t i, j, split, k_prime;
BPTreeNode *new_node, *child; BPTreeNode *new_node, *child;
int *temp_keys; BPTreeKey_t *temp_keys;
BPTreeNode **temp_pointers; BPTreeNode **temp_pointers;
/* First create a temporary set of keys and pointers /* First create a temporary set of keys and pointers
...@@ -495,7 +494,7 @@ BPTreeNode *insert_into_node_after_splitting(BPTreeNode *root, BPTreeNode *old_n ...@@ -495,7 +494,7 @@ BPTreeNode *insert_into_node_after_splitting(BPTreeNode *root, BPTreeNode *old_n
perror("Temporary pointers array for splitting nodes."); perror("Temporary pointers array for splitting nodes.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
temp_keys = calloc((size_t) order, sizeof(int)); temp_keys = calloc((size_t) order, sizeof(BPTreeKey_t));
if (temp_keys == NULL) { if (temp_keys == NULL) {
perror("Temporary keys array for splitting nodes."); perror("Temporary keys array for splitting nodes.");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -554,7 +553,7 @@ BPTreeNode *insert_into_node_after_splitting(BPTreeNode *root, BPTreeNode *old_n ...@@ -554,7 +553,7 @@ BPTreeNode *insert_into_node_after_splitting(BPTreeNode *root, BPTreeNode *old_n
/* Inserts a new node (leaf or internal node) into the B+ tree. /* Inserts a new node (leaf or internal node) into the B+ tree.
* Returns the root of the tree after insertion. * Returns the root of the tree after insertion.
*/ */
BPTreeNode *insert_into_parent(BPTreeNode *root, BPTreeNode *left, int key, BPTreeNode *right) { BPTreeNode *insert_into_parent(BPTreeNode *root, BPTreeNode *left, BPTreeKey_t key, BPTreeNode *right) {
int left_index; int left_index;
BPTreeNode *parent; BPTreeNode *parent;
...@@ -595,7 +594,7 @@ BPTreeNode *insert_into_parent(BPTreeNode *root, BPTreeNode *left, int key, BPTr ...@@ -595,7 +594,7 @@ BPTreeNode *insert_into_parent(BPTreeNode *root, BPTreeNode *left, int key, BPTr
* and inserts the appropriate key into * and inserts the appropriate key into
* the new root. * the new root.