-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAllocation.c
More file actions
54 lines (46 loc) · 980 Bytes
/
Allocation.c
File metadata and controls
54 lines (46 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
CSE 109: Spring 2018
Dylan Spector
drs320
C file for Allocation Object
Program #4
*/
#include"Allocation.h"
#include<stdio.h>
#include<stdlib.h>
void makeAllocation(struct Allocation_t* it, size_t start, size_t size)
{
it->start = start;
it->size = size;
return;
}
void freeAllocation(struct Allocation_t* it)
{
free(it);
return;
}
size_t getStart(struct Allocation_t* it)
{
return it->start;
}
size_t getEnd(struct Allocation_t* it)
{
return (getStart(it) + getSize(it));
}
size_t getSize(struct Allocation_t* it)
{
return it->size;
}
int doesOverlap(struct Allocation_t* it, size_t start, size_t size)
{
size_t inclusiveEnd = (start+size-1);
if(inclusiveEnd == getStart(it) || (inclusiveEnd > getStart(it) && inclusiveEnd < getEnd(it)))
{
return 1; // overlaps from the left
}
else if(getEnd(it)-1 == start || (getEnd(it)-1 > start && getEnd(it)-1 < start+size))
{
return 1; // overlaps from the right
}
return 0; // does not overlap
}