aboutsummaryrefslogtreecommitdiffstats
path: root/libparc/parc/algol/parc_OldSortedList.h
blob: 2a00a0fadea9711f0bcdc6604ad76fc5a7a92638 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @file parc_SortedList.h
 * @ingroup datastructures
 * @brief A sorted list
 *
 */
#ifndef libparc_parc_SortedList_h
#define libparc_parc_SortedList_h

#include <stdlib.h>

struct parc_sorted_list;

typedef struct parc_sorted_list PARCSortedList;

/**
 * This is a compare function that must be defined for the sorted list to sort
 *
 * @param [in] object1 The first object to compare.
 * @param [in] object2 The second object to compare.
 * @return -1 if object1 < object2,  0 if object1 == object2, 1 if object1 > object2.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
typedef int (*parcSortedList_Compare)(const void *object1, const void *object2);

/**
 * Create a sorted list
 * This list will be sorted from smallest to largest based on the compare function.
 *
 * @param [in] compareFunction A compare function to determine how elements are sorted.
 * @return An allocated `PARCSortedList`.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
PARCSortedList *parcSortedList_Create(parcSortedList_Compare compareFunction);

/**
 * Destroy an allocated sorted list
 *
 * @param [in,out] parcSortedListPointer A pointer to the allocated sorted list to destroy. The pointer will be set to NULL.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void parcSortedList_Destroy(PARCSortedList **parcSortedListPointer);

/**
 * Add an element to the sorted list.
 *
 * @param [in,out] parcSortedList A pointer to the `PARCSortedList` to modify.
 * @param newItem The new item to add to the list. This item must be comparable by the compare function.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void parcSortedList_Add(PARCSortedList *parcSortedList, void *newItem);

/**
 * Return the length of the list
 *
 * @param [in] parcSortedList a pointer to an allocated sorted list.
 * @return return the length of the list, the number of elements.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
size_t parcSortedList_Length(PARCSortedList *parcSortedList);

/**
 * Pop the first element on the  sorted list. This will remove the element from the list and return it to the caller.
 *
 * @param [in,out] parcSortedList A pointer to the `PARCSortedList` to modify.
 * @return The first element of @p parcSortedList.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void *parcSortedList_PopFirst(PARCSortedList *parcSortedList);

/**
 * Get the first element on the  sorted list. This will NOT remove the element from the list.
 *
 * @param [in] parcSortedList A pointer to the `PARCSortedList` .
 * @return The first element of the sorted list.
 *
 * Example:
 * @code
 * <#example#>
 * @endcode
 */
void *parcSortedList_GetFirst(PARCSortedList *parcSortedList);
#endif // libparc_parc_SortedList_h