Package Management
list.h
Go to the documentation of this file.
1 
12 #ifndef LIST_H
13 #define LIST_H
14 
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <assert.h>
19 #include "utils.h"
20 
21 #define INT_MIN -2147483647
22 #define EMPTY -23432
23 #define PUSH -232310
24 #define MERGE -2323
25 #define MAX_Q 200000
26 #define MAX_N 200000
27 #define MAX_OP_CHAR 20
28 
30 struct packData;
31 
32 typedef struct pack{
33  int avail; //available?
34  struct pack* prev;
35  struct pack* next;
36  int ID;
37  int (*popfunc)(struct packData, int);
38  int line;
39 } pack;
40 
41 typedef struct List{
42  pack* first;
43  pack* last;
44 } List;
45 
46 
47 typedef struct hnode{
48  struct hnode* leaves[2];
49  int dist;
50  pack* key;
51 } hnode;
52 
54 typedef struct{
55  List list;
56  hnode* heap;
57  int avail;
58 } prodLine;
59 
60 typedef struct packData{
61  int N_Package;
62  int N_Lines;
63  prodLine* lines;
64  pack* packs;
65  hnode* nodes;
66 } packData;
67 
68 
69 
70 typedef struct{
71  int opID;
72  int arg[2];
73 } query;
74 
75 //Solve
76 int solve(packData pd, query* qs, int n_query,int* pkOrders);
77 
78 // Initiation and Deletion
79 
87 packData init_packData(int n, int l);
88 void kill_packData(packData);
89 
90 // Data management
91 void PushPack(packData, int iLine, int iPack);
92 void MergeLines(packData, int iDst, int iSrc);
93 
94 //Pop
95 int PopFirstPack(packData, int iLine);
96 int PopLastPack(packData, int iLine);
97 int PopMaxPack(packData, int iLine);
99 int _PopOperation(packData, int,int (*PeekFunc)(packData,int), int (*PopFunc)(packData,int));
100 
101 // Peak Data
103 int PeekFirstPack(packData, int i);
105 int PeekLastPack(packData, int i);
106 int PeekMaxPack(packData, int i);
107 
109 void _clearGetMethod(packData, int iLine);
110 void _setGetMethod(packData, int iLine);
111 
112 
113 // Heap operation
114 void _insertHeap(packData pd, int iLine, int iPack);
115 int _popMaxHeap(packData, int iLine);
116 void _mergeHeap(packData, int iDst, int iSrc);
117 
118 //Leftist Heap
127 hnode* _popMaxHeapLeftist(hnode* root, int* val);
128 hnode* _insertHeapLeftist(hnode* root, pack* pk, hnode* newnode);
129 int _getDistLeftist(hnode* node);
130 void swaphNode(hnode** A, hnode** B);
131 hnode* createNode(pack* pk, hnode* node);
132 
133 void _killHeap(hnode* root);
134 
135 //Linked list
136 
137 void _insertlist(packData pd, int iLine, int iPack);
138 void _mergelist(packData, int iDst, int iSrc);
144 int _popFirst(packData pd, int iLine);
148 int _popLast(packData pd, int iLine);
149 
150 
151 //Remove Item
152 void _removePack(pack*);
153 void _removePackGetMethod(pack*);
154 
155 //Struct
156 pack getNullPack(void);
157 prodLine getNullProdLine(void);
158 
159 //Interface
160 int _getopID(char*);
161 void _getOperation(query*);
162 void _printRes(int sol);
163 void interface(void);
164 
165 #endif
int _popFirst(packData pd, int iLine)
Pop first item. Set popped item.avail (pack) to zero.
Definition: list.c:419
int _PopOperation(packData, int, int(*PeekFunc)(packData, int), int(*PopFunc)(packData, int))
Definition: list.c:137
int _popLast(packData pd, int iLine)
Similar to _popFirst .
Definition: list.c:443
void _clearGetMethod(packData, int iLine)
Definition: list.c:213
packData init_packData(int n, int l)
Initiate a package management problem.
Definition: list.c:43
hnode * _mergeHeapLeftist(hnode *A, hnode *B)
Merge leftist heap.
Definition: list.c:283
int PeekFirstPack(packData, int i)
Definition: list.c:152
int solve(packData pd, query *qs, int n_query, int *pkOrders)
Definition: list.c:9
int PeekLastPack(packData, int i)
Definition: list.c:173
Definition: list.h:41
Definition: list.h:47
Definition: list.h:60
Definition: list.h:32
Definition: list.h:54
Definition: list.h:70
General Utilities for C language.