-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfill.c
More file actions
67 lines (59 loc) · 1.19 KB
/
Copy pathfill.c
File metadata and controls
67 lines (59 loc) · 1.19 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "hash.h"
void ignore_fill(int **ignore, desc_lst *main, int *cache)
{
int i;
i = 0;
while (i < main->caches_amount)
{
if (cache[i] == 0)
(*ignore)[i] = 0;
else
(*ignore)[i] = 1;
i++;
}
}
int check_ignore(int *ignore, int size)
{
int i;
i = 0;
while (i < size)
{
if (ignore[i] == 1)
return (1);
i++;
}
return (0);
}
int find_best_cache(int num_c, int *request, int *ignore, int *cache_size)
{
int i;
int id;
id = -1;
i = 0;
while (i < num_c)
{
if ((ignore[i] == 1 && cache_size[i] > 0) && ((id == -1) || request[i] > request[id]))
id = i;
i++;
}
return (id);
}
void choose(desc_lst *main, ep_lst *ep, int **cache_size, int ***rez)
{
int id_cache;
int *ignore;
int id_cor_v;
ignore = (int*)malloc(sizeof(int) * main->caches_amount);
ignore_fill(&ignore, main, ep->cache);
while (check_ignore(ignore, main->caches_amount))
{
if ((id_cache = find_best_cache(main->caches_amount, ep->requests, ignore, *cache_size)) == -1)
break ;
while ((id_cor_v = suitable_video_id(main, ep, *rez, (*cache_size)[id_cache])) != -1)
{
(*cache_size)[id_cache] -= main->vid_size[id_cor_v];
(*rez)[id_cache][id_cor_v] = 1;
}
ignore[id_cache] = 0;
}
}