Skip to content

Commit c9c22d4

Browse files
authored
Improve documentation (#48)
1 parent a180f8c commit c9c22d4

16 files changed

Lines changed: 545 additions & 138 deletions

src/array.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ struct internal_array {
3737
* negative
3838
* @param data_size the size of each element in the array; must be positive
3939
*
40-
* @return the newly-initialized array, or NULL if memory allocation error
40+
* @return the newly-initialized array, or NULL if it was not successfully
41+
* initialized due to either invalid input arguments or memory
42+
* allocation error
4143
*/
4244
array array_init(const int element_count, const size_t data_size)
4345
{
@@ -76,7 +78,10 @@ int array_size(array me)
7678
}
7779

7880
/**
79-
* Copies the array to a raw array.
81+
* Copies the array to a raw array. Since it is a copy, the raw array may be
82+
* modified without causing side effects to the array data structure. Memory
83+
* is not allocated, thus the raw array being used for the copy must be
84+
* allocated before this function is called.
8085
*
8186
* @param arr the initialized raw array to copy the array to
8287
* @param me the array to copy to the raw array
@@ -90,10 +95,10 @@ void array_copy_to_array(void *const arr, array me)
9095
}
9196

9297
/**
93-
* Gets the storage element of the array which is contiguous in memory. If the
94-
* data is modified, the data in the array is modified. Also, any array
95-
* operation may invalidate this data pointer. The array owns the data pointer,
96-
* thus it must not be freed.
98+
* Gets the storage element of the array structure. This pointer is not a copy,
99+
* thus any modification to the data will cause the array structure data to be
100+
* modified. Operations using the array functions may invalidate this pointer.
101+
* The array owns this memory, thus it should not be freed.
97102
*
98103
* @param me the array to get the storage element from
99104
*
@@ -113,7 +118,11 @@ static int array_is_illegal_input(array me, const int index)
113118
}
114119

115120
/**
116-
* Sets the data for a specified element in the array.
121+
* Sets the data for a specified element in the array. The pointer to the data
122+
* being passed in should point to the data type which this array holds. For
123+
* example, if this array holds integers, the data pointer should be a pointer
124+
* to an integer. Since the data is being copied, the pointer only has to be
125+
* valid when this function is called.
117126
*
118127
* @param me the array to set data for
119128
* @param index the location to set data at in the array
@@ -133,7 +142,12 @@ int array_set(array me, const int index, void *const data)
133142
}
134143

135144
/**
136-
* Copies the element at index of the array to data.
145+
* Copies the element at index of the array to data. The pointer to the data
146+
* being obtained should point to the data type which this array holds. For
147+
* example, if this array holds integers, the data pointer should be a pointer
148+
* to an integer. Since this data is being copied from the array to the data
149+
* pointer, the pointer only has to be valid when this function is called.
150+
*
137151
*
138152
* @param data the data to copy to
139153
* @param me the array to copy from

src/deque.c

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ struct node {
4444
*
4545
* @param data_size the size of each element in the deque; must be positive
4646
*
47-
* @return the newly-initialized deque, or NULL if memory allocation error
47+
* @return the newly-initialized deque, or NULL if it was not successfully
48+
* initialized due to either invalid input arguments or memory
49+
* allocation error
4850
*/
4951
deque deque_init(const size_t data_size)
5052
{
@@ -145,7 +147,10 @@ int deque_trim(deque me)
145147
}
146148

147149
/**
148-
* Copies the deque to an array.
150+
* Copies the deque to an array. Since it is a copy, the array may be modified
151+
* without causing side effects to the deque data structure. Memory is not
152+
* allocated, thus the array being used for the copy must be allocated before
153+
* this function is called.
149154
*
150155
* @param arr the initialized array to copy the deque to
151156
* @param me the deque to copy to the array
@@ -159,7 +164,11 @@ void deque_copy_to_array(void *const arr, deque me)
159164
}
160165

161166
/**
162-
* Adds an element to the front of the deque.
167+
* Adds an element to the front of the deque. The pointer to the data being
168+
* passed in should point to the data type which this deque holds. For example,
169+
* if this deque holds integers, the data pointer should be a pointer to an
170+
* integer. Since the data is being copied, the pointer only has to be valid
171+
* when this function is called.
163172
*
164173
* @param me the deque to add an element to
165174
* @param data the element to add
@@ -221,7 +230,11 @@ int deque_push_front(deque me, void *const data)
221230
}
222231

223232
/**
224-
* Adds an element to the back of the deque.
233+
* Adds an element to the back of the deque. The pointer to the data being
234+
* passed in should point to the data type which this deque holds. For example,
235+
* if this deque holds integers, the data pointer should be a pointer to an
236+
* integer. Since the data is being copied, the pointer only has to be valid
237+
* when this function is called.
225238
*
226239
* @param me the deque to add an element to
227240
* @param data the element to add
@@ -268,7 +281,12 @@ int deque_push_back(deque me, void *const data)
268281
}
269282

270283
/**
271-
* Removes the front element from the deque and copies it to a data value.
284+
* Removes the front element from the deque and copies it to a data value. The
285+
* pointer to the data being obtained should point to the data type which this
286+
* deque holds. For example, if this deque holds integers, the data pointer
287+
* should be a pointer to an integer. Since this data is being copied from the
288+
* array to the data pointer, the pointer only has to be valid when this
289+
* function is called.
272290
*
273291
* @param data the value to copy to
274292
* @param me the deque to remove from
@@ -294,7 +312,12 @@ int deque_pop_front(void *const data, deque me)
294312
}
295313

296314
/**
297-
* Removes the back element from the deque and copies it to a data value.
315+
* Removes the back element from the deque and copies it to a data value. The
316+
* pointer to the data being obtained should point to the data type which this
317+
* deque holds. For example, if this deque holds integers, the data pointer
318+
* should be a pointer to an integer. Since this data is being copied from the
319+
* array to the data pointer, the pointer only has to be valid when this
320+
* function is called.
298321
*
299322
* @param data the value to copy to
300323
* @param me the deque to remove from
@@ -320,7 +343,11 @@ int deque_pop_back(void *const data, deque me)
320343
}
321344

322345
/**
323-
* Sets the first value of the deque.
346+
* Sets the first value of the deque. The pointer to the data being passed in
347+
* should point to the data type which this deque holds. For example, if this
348+
* deque holds integers, the data pointer should be a pointer to an integer.
349+
* Since the data is being copied, the pointer only has to be valid when this
350+
* function is called.
324351
*
325352
* @param me the deque to set value of
326353
* @param data the data to set
@@ -334,7 +361,11 @@ int deque_set_first(deque me, void *const data)
334361
}
335362

336363
/**
337-
* Sets the value of the deque at the specified index.
364+
* Sets the value of the deque at the specified index. The pointer to the data
365+
* being passed in should point to the data type which this deque holds. For
366+
* example, if this deque holds integers, the data pointer should be a pointer
367+
* to an integer. Since the data is being copied, the pointer only has to be
368+
* valid when this function is called.
338369
*
339370
* @param me the deque to set value of
340371
* @param index the index to set at
@@ -361,7 +392,11 @@ int deque_set_at(deque me, int index, void *const data)
361392
}
362393

363394
/**
364-
* Sets the last value of the deque.
395+
* Sets the last value of the deque. The pointer to the data being passed in
396+
* should point to the data type which this deque holds. For example, if this
397+
* deque holds integers, the data pointer should be a pointer to an integer.
398+
* Since the data is being copied, the pointer only has to be valid when this
399+
* function is called.
365400
*
366401
* @param me the deque to set value of
367402
* @param data the data to set
@@ -375,7 +410,11 @@ int deque_set_last(deque me, void *const data)
375410
}
376411

377412
/**
378-
* Gets the first value of the deque.
413+
* Gets the first value of the deque. The pointer to the data being obtained
414+
* should point to the data type which this deque holds. For example, if this
415+
* deque holds integers, the data pointer should be a pointer to an integer.
416+
* Since this data is being copied from the array to the data pointer, the
417+
* pointer only has to be valid when this function is called.
379418
*
380419
* @param data the data to set
381420
* @param me the deque to set value of
@@ -389,7 +428,11 @@ int deque_get_first(void *const data, deque me)
389428
}
390429

391430
/**
392-
* Gets the value of the deque at the specified index.
431+
* Gets the value of the deque at the specified index. The pointer to the data
432+
* being obtained should point to the data type which this deque holds. For
433+
* example, if this deque holds integers, the data pointer should be a pointer
434+
* to an integer. Since this data is being copied from the array to the data
435+
* pointer, the pointer only has to be valid when this function is called.
393436
*
394437
* @param data the data to set
395438
* @param me the deque to set value of
@@ -416,7 +459,11 @@ int deque_get_at(void *const data, deque me, int index)
416459
}
417460

418461
/**
419-
* Gets the last value of the deque.
462+
* Gets the last value of the deque. The pointer to the data being obtained
463+
* should point to the data type which this deque holds. For example, if this
464+
* deque holds integers, the data pointer should be a pointer to an integer.
465+
* Since this data is being copied from the array to the data pointer, the
466+
* pointer only has to be valid when this function is called.
420467
*
421468
* @param data the data to set
422469
* @param me the deque to set value of

src/forward_list.c

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ struct node {
4040
*
4141
* @param data_size the size of data to store; must be positive
4242
*
43-
* @return the newly-initialized singly-linked list, or NULL if memory
44-
* allocation error
43+
* @return the newly-initialized singly-linked list, or NULL if it was not
44+
* successfully initialized due to either invalid input arguments or
45+
* memory allocation error
4546
*/
4647
forward_list forward_list_init(const size_t data_size)
4748
{
@@ -84,7 +85,10 @@ int forward_list_is_empty(forward_list me)
8485
}
8586

8687
/**
87-
* Copies the nodes of the singly-linked list to an array.
88+
* Copies the nodes of the singly-linked list to an array. Since it is a copy,
89+
* the array may be modified without causing side effects to the singly-linked
90+
* list data structure. Memory is not allocated, thus the array being used for
91+
* the copy must be allocated before this function is called.
8892
*
8993
* @param arr the initialized array to copy the singly-linked list to
9094
* @param me the singly-linked list to copy to the array
@@ -114,7 +118,11 @@ static struct node *forward_list_get_node_at(forward_list me, const int index)
114118
}
115119

116120
/**
117-
* Adds data at the first index in the singly-linked list.
121+
* Adds data at the first index in the singly-linked list. The pointer to the
122+
* data being passed in should point to the data type which this singly-linked
123+
* list holds. For example, if this singly-linked list holds integers, the data
124+
* pointer should be a pointer to an integer. Since the data is being copied,
125+
* the pointer only has to be valid when this function is called.
118126
*
119127
* @param me the singly-linked list to add data to
120128
* @param data the data to add to the singly-linked list
@@ -128,7 +136,11 @@ int forward_list_add_first(forward_list me, void *const data)
128136
}
129137

130138
/**
131-
* Adds data at a specified index in the singly-linked list.
139+
* Adds data at a specified index in the singly-linked list. The pointer to the
140+
* data being passed in should point to the data type which this singly-linked
141+
* list holds. For example, if this singly-linked list holds integers, the data
142+
* pointer should be a pointer to an integer. Since the data is being copied,
143+
* the pointer only has to be valid when this function is called.
132144
*
133145
* @param me the singly-linked list to add data to
134146
* @param index the index to add the data at
@@ -167,7 +179,11 @@ int forward_list_add_at(forward_list me, const int index, void *const data)
167179
}
168180

169181
/**
170-
* Adds data at the last index in the singly-linked list.
182+
* Adds data at the last index in the singly-linked list. The pointer to the
183+
* data being passed in should point to the data type which this singly-linked
184+
* list holds. For example, if this singly-linked list holds integers, the data
185+
* pointer should be a pointer to an integer. Since the data is being copied,
186+
* the pointer only has to be valid when this function is called.
171187
*
172188
* @param me the singly-linked list to add data to
173189
* @param data the data to add to the singly-linked list
@@ -250,7 +266,11 @@ int forward_list_remove_last(forward_list me)
250266
}
251267

252268
/**
253-
* Sets the data at the first index in the singly-linked list.
269+
* Sets the data at the first index in the singly-linked list. The pointer to
270+
* the data being passed in should point to the data type which this singly-
271+
* linked list holds. For example, if this singly-linked list holds integers,
272+
* the data pointer should be a pointer to an integer. Since the data is being
273+
* copied, the pointer only has to be valid when this function is called.
254274
*
255275
* @param me the singly-linked list to set data for
256276
* @param data the data to set in the singly-linked list
@@ -264,7 +284,11 @@ int forward_list_set_first(forward_list me, void *const data)
264284
}
265285

266286
/**
267-
* Sets the data at the specified index in the singly-linked list.
287+
* Sets the data at the specified index in the singly-linked list. The pointer
288+
* to the data being passed in should point to the data type which this singly-
289+
* linked list holds. For example, if this singly-linked list holds integers,
290+
* the data pointer should be a pointer to an integer. Since the data is being
291+
* copied, the pointer only has to be valid when this function is called.
268292
*
269293
* @param me the singly-linked list to set data for
270294
* @param index the index to set data in the singly-linked list
@@ -285,7 +309,11 @@ int forward_list_set_at(forward_list me, const int index, void *const data)
285309
}
286310

287311
/**
288-
* Sets the data at the last index in the singly-linked list.
312+
* Sets the data at the last index in the singly-linked list. The pointer to
313+
* the data being passed in should point to the data type which this singly-
314+
* linked list holds. For example, if this singly-linked list holds integers,
315+
* the data pointer should be a pointer to an integer. Since the data is being
316+
* copied, the pointer only has to be valid when this function is called.
289317
*
290318
* @param me the singly-linked list to set data for
291319
* @param data the data to set in the singly-linked list
@@ -299,7 +327,12 @@ int forward_list_set_last(forward_list me, void *const data)
299327
}
300328

301329
/**
302-
* Gets the data at the first index in the singly-linked list.
330+
* Gets the data at the first index in the singly-linked list. The pointer to
331+
* the data being obtained should point to the data type which this singly-
332+
* linked list holds. For example, if this singly-linked list holds integers,
333+
* the data pointer should be a pointer to an integer. Since this data is being
334+
* copied from the array to the data pointer, the pointer only has to be valid
335+
* when this function is called.
303336
*
304337
* @param data the data to get
305338
* @param me the singly-linked list to get data from
@@ -313,7 +346,12 @@ int forward_list_get_first(void *const data, forward_list me)
313346
}
314347

315348
/**
316-
* Gets the data at the specified index in the singly-linked list.
349+
* Gets the data at the specified index in the singly-linked list. The pointer
350+
* to the data being obtained should point to the data type which this singly-
351+
* linked list holds. For example, if this singly-linked list holds integers,
352+
* the data pointer should be a pointer to an integer. Since this data is being
353+
* copied from the array to the data pointer, the pointer only has to be valid
354+
* when this function is called.
317355
*
318356
* @param data the data to get
319357
* @param me the singly-linked list to get data from
@@ -334,7 +372,12 @@ int forward_list_get_at(void *const data, forward_list me, const int index)
334372
}
335373

336374
/**
337-
* Gets the data at the last index in the singly-linked list.
375+
* Gets the data at the last index in the singly-linked list. The pointer to
376+
* the data being obtained should point to the data type which this singly-
377+
* linked list holds. For example, if this singly-linked list holds integers,
378+
* the data pointer should be a pointer to an integer. Since this data is being
379+
* copied from the array to the data pointer, the pointer only has to be valid
380+
* when this function is called.
338381
*
339382
* @param data the data to get
340383
* @param me the singly-linked list to get data from

0 commit comments

Comments
 (0)