-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathIsraeliQueue.h
85 lines (66 loc) · 3.81 KB
/
IsraeliQueue.h
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef PROVIDED_ISRAELIQUEUE_H
#define PROVIDED_ISRAELIQUEUE_H
#include <stdbool.h>
#define FRIEND_QUOTA 5
#define RIVAL_QUOTA 3
typedef struct IsraeliQueue_t * IsraeliQueue;
typedef int (*FriendshipFunction)(void*,void*);
typedef int (*ComparisonFunction)(void*,void*);
typedef enum { ISRAELIQUEUE_SUCCESS, ISRAELIQUEUE_ALLOC_FAILED, ISRAELIQUEUE_BAD_PARAM, ISRAELI_QUEUE_ERROR } IsraeliQueueError;
/**Error clarification:
* ISRAELIQUEUE_SUCCESS: Indicates the function has completed its task successfully with no errors.
* ISRAELIQUEUE_ALLOC_FAILED: Indicates memory allocation failed during the execution of the function.
* ISRAELIQUEUE_BAD_PARAM: Indicates an illegal parameter was passed.
* ISRAELI_QUEUE_ERROR: Indicates any error beyond the above.
* */
/**Creates a new IsraeliQueue_t object with the provided friendship functions, a NULL-terminated array,
* comparison function, friendship threshold and rivalry threshold. Returns a pointer
* to the new object. In case of failure, return NULL.*/
IsraeliQueue IsraeliQueueCreate(FriendshipFunction *, ComparisonFunction, int, int);
/**Returns a new queue with the same elements as the parameter. If the parameter is NULL or any error occured during
* the execution of the function, NULL is returned.*/
IsraeliQueue IsraeliQueueClone(IsraeliQueue q);
/**@param IsraeliQueue: an IsraeliQueue created by IsraeliQueueCreate
*
* Deallocates all memory allocated by IsraeliQueueCreate for the object pointed to by
* the parameter.*/
void IsraeliQueueDestroy(IsraeliQueue);
/**@param IsraeliQueue: an IsraeliQueue in which to insert the item.
* @param item: an item to enqueue
*
* Places the item in the foremost position accessible to it.*/
IsraeliQueueError IsraeliQueueEnqueue(IsraeliQueue, void *);
/**@param IsraeliQueue: an IsraeliQueue to which the function is to be added
* @param FriendshipFunction: a FriendshipFunction to be recognized by the IsraeliQueue
* going forward.
*
* Makes the IsraeliQueue provided recognize the FriendshipFunction provided.*/
IsraeliQueueError IsraeliQueueAddFriendshipMeasure(IsraeliQueue, FriendshipFunction);
/**@param IsraeliQueue: an IsraeliQueue whose friendship threshold is to be modified
* @param friendship_threshold: a new friendship threshold for the IsraeliQueue*/
IsraeliQueueError IsraeliQueueUpdateFriendshipThreshold(IsraeliQueue, int);
/**@param IsraeliQueue: an IsraeliQueue whose rivalry threshold is to be modified
* @param friendship_threshold: a new rivalry threshold for the IsraeliQueue*/
IsraeliQueueError IsraeliQueueUpdateRivalryThreshold(IsraeliQueue, int);
/**Returns the number of elements of the given queue. If the parameter is NULL, 0
* is returned.*/
int IsraeliQueueSize(IsraeliQueue);
/**Removes and returns the foremost element of the provided queue. If the parameter
* is NULL or a pointer to an empty queue, NULL is returned.*/
void* IsraeliQueueDequeue(IsraeliQueue);
/**@param item: an object comparable to the objects in the IsraeliQueue
*
* Returns whether the queue contains an element equal to item. If either
* parameter is NULL, false is returned.*/
bool IsraeliQueueContains(IsraeliQueue, void *);
/**Advances each item in the queue to the foremost position accessible to it,
* from the back of the queue frontwards.*/
IsraeliQueueError IsraeliQueueImprovePositions(IsraeliQueue);
/**@param q_arr: a NULL-terminated array of IsraeliQueues
* @param ComparisonFunction: a comparison function for the merged queue
*
* Merges all queues in q_arr into a single new queue, with parameters the parameters described
* in the exercise. Each queue in q_arr enqueues its head in the merged queue, then lets the next
* one enqueue an item, in the order defined by q_arr. In the event of any error during execution, return NULL.*/
IsraeliQueue IsraeliQueueMerge(IsraeliQueue*,ComparisonFunction);
#endif //PROVIDED_ISRAELIQUEUE_H