All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
as_arraylist.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2019 Aerospike, Inc.
3  *
4  * Portions may be licensed to Aerospike, Inc. under one or more contributor
5  * license agreements.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
8  * use this file except in compliance with the License. You may obtain a copy of
9  * the License at http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14  * License for the specific language governing permissions and limitations under
15  * the License.
16  */
17 #pragma once
18 
19 #include <aerospike/as_bytes.h>
20 #include <aerospike/as_double.h>
21 #include <aerospike/as_integer.h>
22 #include <aerospike/as_list.h>
23 #include <aerospike/as_map.h>
24 #include <aerospike/as_std.h>
25 #include <aerospike/as_string.h>
26 #include <aerospike/as_val.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /******************************************************************************
33  * TYPES
34  *****************************************************************************/
35 
36 /**
37  * An dynamic array implementation for as_list.
38  *
39  * as_arryalist can either be initialize on the stack or the heap.
40  *
41  * For stack allocation, you have two choices:
42  * - `as_arraylist_init()` - uses `cf_malloc()` to initialize the internal storage
43  * on the heap.
44  * - `as_arraylist_inita()` - uses `alloca()` to initialize the internal storage
45  * on the stack.
46  *
47  * The key differences between the two is `as_arraylist_inita()` can't be
48  * dynamically resized and is solely on the stack.
49  *
50  * The following is using a `as_arraylist_inita()`:
51  * ~~~~~~~~~~{.c}
52  * as_arraylist list;
53  * as_arraylist_inita(&list, 2);
54  * ~~~~~~~~~~
55  *
56  * You will notice that the code is quite similar to `as_arraylist_init()`:
57  * ~~~~~~~~~~{.c}
58  * as_arraylist list;
59  * as_arraylist_init(&list, 2, 0);
60  * ~~~~~~~~~~
61  *
62  * If you need a new heap allocated list, then use `as_arraylist_new()`:
63  *
64  * ~~~~~~~~~~{.c}
65  * as_arraylist* list = as_arraylist_new(2, 0);
66  * ~~~~~~~~~~
67  *
68  * When you are finished using the list, then you should release the list and
69  * associated resources, using `as_arraylist_destroy()`:
70  *
71  * ~~~~~~~~~~{.c}
72  * as_arraylist_destroy(list);
73  * ~~~~~~~~~~
74  *
75  * The `as_arraylist` is a subtype of `as_list`. This allows you to
76  * alternatively use `as_list` functions, by typecasting `as_arraylist` to
77  * `as_list`.
78  *
79  * ~~~~~~~~~~{.c}
80  * as_arraylist list;
81  * as_list * l = (as_list *) as_arraylist_init(&list, 3, 0);
82  * as_list_append_int64(l, 1);
83  * as_list_append_int64(l, 2);
84  * as_list_append_int64(l, 3);
85  * as_list_destroy(l);
86  * ~~~~~~~~~~
87  *
88  * Each of the `as_list` functions proxy to the `as_arraylist` functions.
89  * So, calling `as_list_destroy()` is equivalent to calling
90  * `as_arraylist_destroy()`.
91  *
92  * @extends as_list
93  * @ingroup aerospike_t
94  */
95 typedef struct as_arraylist_s {
96 
97  /**
98  * @private
99  * as_arraylist is an as_list.
100  * You can cast as_arraylist to as_list.
101  */
102  as_list _;
103 
104  /**
105  * Number of elements to add, when capacity is reached.
106  * If 0 (zero), then capacity can't be expanded.
107  */
108  uint32_t block_size;
109 
110  /**
111  * The total number elements allocated.
112  */
113  uint32_t capacity;
114 
115  /**
116  * The number of elements used.
117  */
118  uint32_t size;
119 
120  /**
121  * The elements of the list.
122  */
124 
125  /**
126  * If true, then as_arraylist.elements will be freed when
127  * as_arraylist_destroy() is called.
128  */
129  bool free;
130 
131 } as_arraylist;
132 
133 /**
134  * Status codes for various as_arraylist operations.
135  */
136 typedef enum as_arraylist_status_e {
137 
138  /**
139  * Normal operation.
140  */
142 
143  /**
144  * Unable to expand capacity, because cf_realloc() failed.
145  */
147 
148  /**
149  * Unable to expand capacity, because as_arraylist.block_size is 0.
150  */
152 
153  /**
154  * Illegal array index.
155  */
157 
159 
160 /******************************************************************************
161  * MACROS
162  ******************************************************************************/
163 
164 /**
165  * Initialize a stack allocated as_arraylist, with element storage on
166  * the stack.
167  *
168  * This differs from as_arraylist_init(), in that as_arraylist_init()
169  * allocates element storage on the heap.
170  *
171  * @param __list The as_list to initialize
172  * @param __n The number of elements to allocate to the list.
173  *
174  * @return On success, the initialize list. Otherwise NULL.
175  * @relatesalso as_arraylist
176  */
177 #define as_arraylist_inita(__list, __n)\
178  as_arraylist_init((__list), 0, 0);\
179  (__list)->free = false;\
180  (__list)->capacity = (__n);\
181  (__list)->size = 0;\
182  (__list)->elements = (as_val**) alloca(sizeof(as_val*) * (__n));
183 
184 /*******************************************************************************
185  * INSTANCE FUNCTIONS
186  ******************************************************************************/
187 
188 /**
189  * Initialize a stack allocated as_arraylist, with element storage on the
190  * heap.
191  *
192  * This differs from as_arraylist_inita(), in that as_arraylist_inita()
193  * allocates element storage on the stack.
194  *
195  * @param list The as_list to initialize
196  * @param capacity The number of elements to allocate to the list.
197  * @param block_size The number of elements to grow the list by, when the
198  * capacity has been reached.
199  *
200  * @return On success, the initialize list. Otherwise NULL.
201  * @relatesalso as_arraylist
202  */
204 as_arraylist_init(as_arraylist* list, uint32_t capacity, uint32_t block_size);
205 
206 /**
207  * Create and initialize a heap allocated list as as_arraylist.
208  *
209  * @param capacity The number of elements to allocate to the list.
210  * @param block_size The number of elements to grow the list by, when the
211  * capacity has been reached.
212  *
213  * @return On success, the new list. Otherwise NULL.
214  * @relatesalso as_arraylist
215  */
217 as_arraylist_new(uint32_t capacity, uint32_t block_size);
218 
219 /**
220  * Destoy the list and release resources.
221  *
222  * @param list The list to destroy.
223  * @relatesalso as_arraylist
224  */
225 AS_EXTERN void
227 
228 /*******************************************************************************
229  * VALUE FUNCTIONS
230  ******************************************************************************/
231 
232 /**
233  * The hash value of the list.
234  *
235  * @param list The list.
236  *
237  * @return The hash value of the list.
238  * @relatesalso as_arraylist
239  */
240 AS_EXTERN uint32_t
242 
243 /**
244  * The number of elements in the list.
245  *
246  * @param list The list.
247  *
248  * @return The number of elements in the list.
249  * @relatesalso as_arraylist
250  */
251 AS_EXTERN uint32_t
252 as_arraylist_size(const as_arraylist* list);
253 
254 /*******************************************************************************
255  * ACCESSOR AND MODIFIER FUNCTIONS
256  ******************************************************************************/
257 
258 /**
259  * Append all elements of list2, in order, to list. No new list object is
260  * created.
261  *
262  * @param list The list to append to.
263  * @param list2 The list from which to append.
264  *
265  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
266  * @relatesalso as_arraylist
267  */
268 AS_EXTERN int
269 as_arraylist_concat(as_arraylist* list, const as_arraylist* list2);
270 
271 /**
272  * Delete (and destroy) all elements at and beyond specified index. Capacity is
273  * not reduced.
274  *
275  * @param list The list to trim.
276  * @param index The index from which to trim.
277  *
278  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
279  * @relatesalso as_arraylist
280  */
281 AS_EXTERN int
282 as_arraylist_trim(as_arraylist* list, uint32_t index);
283 
284 /**
285  * Get the first element of the list.
286  *
287  * @param list The list to get the first element from.
288  *
289  * @return The first element of the list. Otherwise NULL.
290  * @relatesalso as_arraylist
291  */
293 as_arraylist_head(const as_arraylist* list);
294 
295 /**
296  * Returns a new list containing all elements other than the head
297  *
298  * @param list The list to get the elements from.
299  *
300  * @return A new list of all elements after the first element.
301  * @relatesalso as_arraylist
302  */
304 as_arraylist_tail(const as_arraylist* list);
305 
306 /**
307  * Return a new list with the first n elements removed.
308  *
309  * @param list The list.
310  * @param n The number of elements to remove.
311  *
312  * @return A new list of all elements after the first n elements.
313  * @relatesalso as_arraylist
314  */
316 as_arraylist_drop(const as_arraylist* list, uint32_t n);
317 
318 /**
319  * Return a new list containing the first n elements.
320  *
321  * @param list The list.
322  * @param n The number of elements to take.
323  *
324  * @return A new list of the first n elements.
325  * @relatesalso as_arraylist
326  */
328 as_arraylist_take(const as_arraylist* list, uint32_t n);
329 
330 /******************************************************************************
331  * GET FUNCTIONS
332  ******************************************************************************/
333 
334 /**
335  * Return the value at the specified index.
336  *
337  * @param list The list.
338  * @param index The index of the element.
339  *
340  * @return The value at given index, if it exists. Otherwise NULL.
341  * @relatesalso as_arraylist
342  */
344 as_arraylist_get(const as_arraylist* list, uint32_t index);
345 
346 /**
347  * Return an int64_t value at the specified index of the list.
348  *
349  * @param list The list.
350  * @param index The index of the element.
351  *
352  * @return The value at given index, if it exists. Otherwise NULL.
353  * @relatesalso as_arraylist
354  */
355 AS_EXTERN int64_t
356 as_arraylist_get_int64(const as_arraylist* list, uint32_t index);
357 
358 /**
359  * Return a double value at the specified index of the list.
360  *
361  * @param list The list.
362  * @param index The index of the element.
363  *
364  * @return The value at given index, if it exists. Otherwise NULL.
365  * @relatesalso as_arraylist
366  */
367 AS_EXTERN double
368 as_arraylist_get_double(const as_arraylist* list, uint32_t index);
369 
370 /**
371  * Return a NULL-terminated value at the specified index of the list.
372  *
373  * @param list The list.
374  * @param index The index of the element.
375  *
376  * @return The value at given index, if it exists. Otherwise NULL.
377  * @relatesalso as_arraylist
378  */
379 AS_EXTERN char*
380 as_arraylist_get_str(const as_arraylist* list, uint32_t index);
381 
382 /**
383  * Return an as_integer value at the specified index of the list.
384  *
385  * @param list The list.
386  * @param index The index of the element.
387  *
388  * @return The value at given index, if it exists. Otherwise NULL.
389  * @relatesalso as_arraylist
390  */
391 static inline as_integer*
392 as_arraylist_get_integer(const as_arraylist* list, uint32_t index)
393 {
394  return as_integer_fromval(as_arraylist_get(list, index));
395 }
396 
397 /**
398  * Return an as_double value at the specified index of the list.
399  *
400  * @param list The list.
401  * @param index The index of the element.
402  *
403  * @return The value at given index, if it exists. Otherwise NULL.
404  * @relatesalso as_arraylist
405  */
406 static inline as_double*
407 as_arraylist_get_as_double(const as_arraylist* list, uint32_t index)
408 {
409  return as_double_fromval(as_arraylist_get(list, index));
410 }
411 
412 /**
413  * Return an as_string value at the specified index of the list.
414  *
415  * @param list The list.
416  * @param index The index of the element.
417  *
418  * @return The value at given index, if it exists. Otherwise NULL.
419  * @relatesalso as_arraylist
420  */
421 static inline as_string*
422 as_arraylist_get_string(const as_arraylist* list, uint32_t index)
423 {
424  return as_string_fromval(as_arraylist_get(list, index));
425 }
426 
427 /**
428  * Return an as_bytes value at the specified index of the list.
429  *
430  * @param list The list.
431  * @param index The index of the element.
432  *
433  * @return The value at given index, if it exists. Otherwise NULL.
434  * @relatesalso as_arraylist
435  */
436 static inline as_bytes*
437 as_arraylist_get_bytes(const as_arraylist* list, uint32_t index)
438 {
439  return as_bytes_fromval(as_arraylist_get(list, index));
440 }
441 
442 /**
443  * Return an as_list value at the specified index of the list.
444  *
445  * @param list The list.
446  * @param index The index of the element.
447  *
448  * @return The value at given index, if it exists. Otherwise NULL.
449  * @relatesalso as_arraylist
450  */
451 static inline as_list*
452 as_arraylist_get_list(const as_arraylist* list, uint32_t index)
453 {
454  return as_list_fromval(as_arraylist_get(list, index));
455 }
456 
457 /**
458  * Return an as_map value at the specified index of the list.
459  *
460  * @param list The list.
461  * @param index The index of the element.
462  *
463  * @return The value at given index, if it exists. Otherwise NULL.
464  * @relatesalso as_arraylist
465  */
466 static inline as_map*
467 as_arraylist_get_map(const as_arraylist* list, uint32_t index)
468 {
469  return as_map_fromval(as_arraylist_get(list, index));
470 }
471 
472 /******************************************************************************
473  * SET FUNCTIONS
474  ******************************************************************************/
475 
476 /**
477  * Set a value at the specified index of the list.
478  *
479  * Notice that in order to maintain proper object/memory management, we
480  * just first destroy (as_val_destroy()) the old object at element position(i)
481  * before assigning the new element. Also note that the object at element
482  * position (i) is assumed to exist, so all element positions must be
483  * appropriately initialized to zero.
484  *
485  * @param list The list.
486  * @param index Position in the list.
487  * @param value The value to set at the given index.
488  *
489  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
490  * @relatesalso as_arraylist
491  */
492 AS_EXTERN int
493 as_arraylist_set(as_arraylist* list, uint32_t index, as_val* value);
494 
495 /**
496  * Set an int64_t value at the specified index of the list.
497  *
498  * @param list The list.
499  * @param index Position in the list.
500  * @param value The value to set at the given index.
501  *
502  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
503  * @relatesalso as_arraylist
504  */
505 AS_EXTERN int
506 as_arraylist_set_int64(as_arraylist* list, uint32_t index, int64_t value);
507 
508 /**
509  * Set a double value at the specified index of the list.
510  *
511  * @param list The list.
512  * @param index Position in the list.
513  * @param value The value to set at the given index.
514  *
515  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
516  * @relatesalso as_arraylist
517  */
518 AS_EXTERN int
519 as_arraylist_set_double(as_arraylist* list, uint32_t index, double value);
520 
521 /**
522  * Set a NULL-terminated string value at the specified index of the list.
523  *
524  * @param list The list.
525  * @param index Position in the list.
526  * @param value The value to set at the given index.
527  *
528  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
529  * @relatesalso as_arraylist
530  */
531 AS_EXTERN int
532 as_arraylist_set_str(as_arraylist* list, uint32_t index, const char* value);
533 
534 /**
535  * Set an as_integer value at the specified index of the list.
536  *
537  * @param list The list.
538  * @param index Position in the list.
539  * @param value The value to set at the given index.
540  *
541  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
542  * @relatesalso as_arraylist
543  */
544 static inline int
545 as_arraylist_set_integer(as_arraylist* list, uint32_t index, as_integer* value)
546 {
547  return as_arraylist_set(list, index, (as_val*) value);
548 }
549 
550 /**
551  * Set an as_double value at the specified index of the list.
552  *
553  * @param list The list.
554  * @param index Position in the list.
555  * @param value The value to set at the given index.
556  *
557  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
558  * @relatesalso as_arraylist
559  */
560 static inline int
561 as_arraylist_set_as_double(as_arraylist* list, uint32_t index, as_double* value)
562 {
563  return as_arraylist_set(list, index, (as_val*) value);
564 }
565 
566 /**
567  * Set an as_string value at the specified index of the list.
568  *
569  * @param list The list.
570  * @param index Position in the list.
571  * @param value The value to set at the given index.
572  *
573  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
574  * @relatesalso as_arraylist
575  */
576 static inline int
577 as_arraylist_set_string(as_arraylist* list, uint32_t index, as_string* value)
578 {
579  return as_arraylist_set(list, index, (as_val*) value);
580 }
581 
582 /**
583  * Set an as_bytes value at the specified index of the list.
584  *
585  * @param list The list.
586  * @param index Position in the list.
587  * @param value The value to set at the given index.
588  *
589  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
590  * @relatesalso as_arraylist
591  */
592 static inline int
593 as_arraylist_set_bytes(as_arraylist* list, uint32_t index, as_bytes* value)
594 {
595  return as_arraylist_set(list, index, (as_val*) value);
596 }
597 
598 /**
599  * Set an as_list value at the specified index of the list.
600  *
601  * @param list The list.
602  * @param index Position in the list.
603  * @param value The value to set at the given index.
604  *
605  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
606  * @relatesalso as_arraylist
607  */
608 static inline int
609 as_arraylist_set_list(as_arraylist* list, uint32_t index, as_list* value)
610 {
611  return as_arraylist_set(list, index, (as_val*) value);
612 }
613 
614 /**
615  * Set an as_map value at the specified index of the list.
616  *
617  * @param list The list.
618  * @param index Position in the list.
619  * @param value The value to set at the given index.
620  *
621  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
622  * @relatesalso as_arraylist
623  */
624 static inline int
625 as_arraylist_set_map(as_arraylist* list, uint32_t index, as_map* value)
626 {
627  return as_arraylist_set(list, index, (as_val*) value);
628 }
629 
630 /******************************************************************************
631  * INSERT FUNCTIONS
632  ******************************************************************************/
633 
634 /**
635  * Insert a value at the specified index of the list.
636  *
637  * Any elements at and beyond specified index will be shifted so their indexes
638  * increase by 1. It's ok to insert beyond the current end of the list.
639  *
640  * @param list The list.
641  * @param index Position in the list.
642  * @param value The value to insert at the given index.
643  *
644  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
645  * @relatesalso as_arraylist
646  */
647 AS_EXTERN int
648 as_arraylist_insert(as_arraylist* list, uint32_t index, as_val* value);
649 
650 /**
651  * Insert an int64_t value at the specified index of the list.
652  *
653  * @param list The list.
654  * @param index Position in the list.
655  * @param value The value to insert at the given index.
656  *
657  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
658  * @relatesalso as_arraylist
659  */
660 AS_EXTERN int
661 as_arraylist_insert_int64(as_arraylist* list, uint32_t index, int64_t value);
662 
663 /**
664  * Insert a double value at the specified index of the list.
665  *
666  * @param list The list.
667  * @param index Position in the list.
668  * @param value The value to insert at the given index.
669  *
670  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
671  * @relatesalso as_arraylist
672  */
673 AS_EXTERN int
674 as_arraylist_insert_double(as_arraylist* list, uint32_t index, double value);
675 
676 /**
677  * Insert a NULL-terminated string value at the specified index of the list.
678  *
679  * @param list The list.
680  * @param index Position in the list.
681  * @param value The value to insert at the given index.
682  *
683  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
684  * @relatesalso as_arraylist
685  */
686 AS_EXTERN int
687 as_arraylist_insert_str(as_arraylist* list, uint32_t index, const char* value);
688 
689 /**
690  * Insert an as_integer value at the specified index of the list.
691  *
692  * @param list The list.
693  * @param index Position in the list.
694  * @param value The value to insert at the given index.
695  *
696  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
697  * @relatesalso as_arraylist
698  */
699 static inline int
701 {
702  return as_arraylist_insert(list, index, (as_val*) value);
703 }
704 
705 /**
706  * Insert an as_double value at the specified index of the list.
707  *
708  * @param list The list.
709  * @param index Position in the list.
710  * @param value The value to insert at the given index.
711  *
712  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
713  * @relatesalso as_arraylist
714  */
715 static inline int
717 {
718  return as_arraylist_insert(list, index, (as_val*) value);
719 }
720 
721 /**
722  * Insert an as_string value at the specified index of the list.
723  *
724  * @param list The list.
725  * @param index Position in the list.
726  * @param value The value to insert at the given index.
727  *
728  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
729  * @relatesalso as_arraylist
730  */
731 static inline int
732 as_arraylist_insert_string(as_arraylist* list, uint32_t index, as_string* value)
733 {
734  return as_arraylist_insert(list, index, (as_val*) value);
735 }
736 
737 /**
738  * Insert an as_bytes value at the specified index of the list.
739  *
740  * @param list The list.
741  * @param index Position in the list.
742  * @param value The value to insert at the given index.
743  *
744  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
745  * @relatesalso as_arraylist
746  */
747 static inline int
748 as_arraylist_insert_bytes(as_arraylist* list, uint32_t index, as_bytes* value)
749 {
750  return as_arraylist_insert(list, index, (as_val*) value);
751 }
752 
753 /**
754  * Insert an as_list value at the specified index of the list.
755  *
756  * @param list The list.
757  * @param index Position in the list.
758  * @param value The value to insert at the given index.
759  *
760  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
761  * @relatesalso as_arraylist
762  */
763 static inline int
764 as_arraylist_insert_list(as_arraylist* list, uint32_t index, as_list* value)
765 {
766  return as_arraylist_insert(list, index, (as_val*) value);
767 }
768 
769 /**
770  * Insert an as_map value at the specified index of the list.
771  *
772  * @param list The list.
773  * @param index Position in the list.
774  * @param value The value to insert at the given index.
775  *
776  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
777  * @relatesalso as_arraylist
778  */
779 static inline int
780 as_arraylist_insert_map(as_arraylist* list, uint32_t index, as_map* value)
781 {
782  return as_arraylist_insert(list, index, (as_val*) value);
783 }
784 
785 /******************************************************************************
786  * APPEND FUNCTIONS
787  ******************************************************************************/
788 
789 /**
790  * Add the value to the end of the list.
791  *
792  * @param list The list.
793  * @param value The value to prepend.
794  *
795  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
796  * @relatesalso as_arraylist
797  */
798 AS_EXTERN int
800 
801 /**
802  * Add an int64_t to the end of the list.
803  *
804  * @param list The list.
805  * @param value The value to prepend.
806  *
807  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
808  * @relatesalso as_arraylist
809  */
810 AS_EXTERN int
811 as_arraylist_append_int64(as_arraylist* list, int64_t value);
812 
813 /**
814  * Add a double to the end of the list.
815  *
816  * @param list The list.
817  * @param value The value to prepend.
818  *
819  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
820  * @relatesalso as_arraylist
821  */
822 AS_EXTERN int
823 as_arraylist_append_double(as_arraylist* list, double value);
824 
825 /**
826  * Add a NULL-terminated string to the end of the list.
827  *
828  * @param list The list.
829  * @param value The value to prepend.
830  *
831  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
832  * @relatesalso as_arraylist
833  */
834 AS_EXTERN int
835 as_arraylist_append_str(as_arraylist* list, const char* value);
836 
837 /**
838  * Add an as_integer to the end of the list.
839  *
840  * @param list The list.
841  * @param value The value to prepend.
842  *
843  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
844  * @relatesalso as_arraylist
845  */
846 static inline int
848 {
849  return as_arraylist_append(list, (as_val*) value);
850 }
851 
852 /**
853  * Add an as_double to the end of the list.
854  *
855  * @param list The list.
856  * @param value The value to prepend.
857  *
858  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
859  * @relatesalso as_arraylist
860  */
861 static inline int
863 {
864  return as_arraylist_append(list, (as_val*) value);
865 }
866 
867 /**
868  * Add an as_string to the end of the list.
869  *
870  * @param list The list.
871  * @param value The value to prepend.
872  *
873  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
874  * @relatesalso as_arraylist
875  */
876 static inline int
878 {
879  return as_arraylist_append(list, (as_val*) value);
880 }
881 
882 /**
883  * Add an as_bytes to the end of the list.
884  *
885  * @param list The list.
886  * @param value The value to prepend.
887  *
888  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
889  * @relatesalso as_arraylist
890  */
891 static inline int
893 {
894  return as_arraylist_append(list, (as_val*) value);
895 }
896 
897 /**
898  * Add an as_list to the end of the list.
899  *
900  * @param list The list.
901  * @param value The value to prepend.
902  *
903  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
904  * @relatesalso as_arraylist
905  */
906 static inline int
908 {
909  return as_arraylist_append(list, (as_val*) value);
910 }
911 
912 /**
913  * Add an as_map to the end of the list.
914  *
915  * @param list The list.
916  * @param value The value to prepend.
917  *
918  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
919  * @relatesalso as_arraylist
920  */
921 static inline int
923 {
924  return as_arraylist_append(list, (as_val*) value);
925 }
926 
927 /******************************************************************************
928  * PREPEND FUNCTIONS
929  ******************************************************************************/
930 
931 /**
932  * Add the value to the beginning of the list.
933  *
934  * @param list The list.
935  * @param value The value to prepend.
936  *
937  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
938  * @relatesalso as_arraylist
939  */
940 AS_EXTERN int
942 
943 /**
944  * Add an int64_t to the beginning of the list.
945  *
946  * @param list The list.
947  * @param value The value to prepend.
948  *
949  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
950  * @relatesalso as_arraylist
951  */
952 AS_EXTERN int
953 as_arraylist_prepend_int64(as_arraylist* list, int64_t value);
954 
955 /**
956  * Add a double to the beginning of the list.
957  *
958  * @param list The list.
959  * @param value The value to prepend.
960  *
961  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
962  * @relatesalso as_arraylist
963  */
964 AS_EXTERN int
965 as_arraylist_prepend_double(as_arraylist* list, double value);
966 
967 /**
968  * Add a NULL-terminated string to the beginning of the list.
969  *
970  * @param list The list.
971  * @param value The value to prepend.
972  *
973  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
974  * @relatesalso as_arraylist
975  */
976 AS_EXTERN int
977 as_arraylist_prepend_str(as_arraylist* list, const char* value);
978 
979 /**
980  * Add an as_integer to the beginning of the list.
981  *
982  * @param list The list.
983  * @param value The value to prepend.
984  *
985  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
986  * @relatesalso as_arraylist
987  */
988 static inline int
990 {
991  return as_arraylist_prepend(list, (as_val*) value);
992 }
993 
994 /**
995  * Add an as_double to the beginning of the list.
996  *
997  * @param list The list.
998  * @param value The value to prepend.
999  *
1000  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
1001  * @relatesalso as_arraylist
1002  */
1003 static inline int
1005 {
1006  return as_arraylist_prepend(list, (as_val*) value);
1007 }
1008 
1009 /**
1010  * Add an as_string to the beginning of the list.
1011  *
1012  * @param list The list.
1013  * @param value The value to prepend.
1014  *
1015  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
1016  * @relatesalso as_arraylist
1017  */
1018 static inline int as_arraylist_prepend_string(as_arraylist* list, as_string* value)
1019 {
1020  return as_arraylist_prepend(list, (as_val*) value);
1021 }
1022 
1023 /**
1024  * Add an as_bytes to the beginning of the list.
1025  *
1026  * @param list The list.
1027  * @param value The value to prepend.
1028  *
1029  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
1030  * @relatesalso as_arraylist
1031  */
1032 static inline int as_arraylist_prepend_bytes(as_arraylist* list, as_bytes* value)
1033 {
1034  return as_arraylist_prepend(list, (as_val*) value);
1035 }
1036 
1037 /**
1038  * Add an as_list to the beginning of the list.
1039  *
1040  * @param list The list.
1041  * @param value The value to prepend.
1042  *
1043  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
1044  * @relatesalso as_arraylist
1045  */
1046 static inline int as_arraylist_prepend_list(as_arraylist* list, as_list* value)
1047 {
1048  return as_arraylist_prepend(list, (as_val*) value);
1049 }
1050 
1051 /**
1052  * Add an as_map to the beginning of the list.
1053  *
1054  * @param list The list.
1055  * @param value The value to prepend.
1056  *
1057  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
1058  * @relatesalso as_arraylist
1059  */
1060 static inline int as_arraylist_prepend_map(as_arraylist* list, as_map* value)
1061 {
1062  return as_arraylist_prepend(list, (as_val*) value);
1063 }
1064 
1065 /*******************************************************************************
1066  * REMOVE FUNCTION
1067  ******************************************************************************/
1068 
1069 /**
1070  * Remove element at specified index.
1071  *
1072  * Any elements beyond specified index will be shifted so their indexes
1073  * decrease by 1. The element at specified index will be destroyed.
1074  *
1075  * @param list The list.
1076  * @param index The index of the element to remove.
1077  *
1078  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
1079  * @relatesalso as_arraylist
1080  */
1081 AS_EXTERN int
1082 as_arraylist_remove(as_arraylist* list, uint32_t index);
1083 
1084 /******************************************************************************
1085  * ITERATION FUNCTIONS
1086  ******************************************************************************/
1087 
1088 /**
1089  * Call the callback function for each element in the list.
1090  *
1091  * @param list The list to iterate.
1092  * @param callback The function to call for each element in the list.
1093  * @param udata User-data to be sent to the callback.
1094  *
1095  * @return true if iteration completes fully. false if iteration was aborted.
1096  *
1097  * @relatesalso as_arraylist
1098  */
1099 AS_EXTERN bool
1100 as_arraylist_foreach(const as_arraylist* list, as_list_foreach_callback callback, void* udata);
1101 
1102 #ifdef __cplusplus
1103 } // end extern "C"
1104 #endif
AS_EXTERN int as_arraylist_prepend_str(as_arraylist *list, const char *value)
static int as_arraylist_insert_string(as_arraylist *list, uint32_t index, as_string *value)
Definition: as_arraylist.h:732
static as_integer * as_integer_fromval(const as_val *v)
Definition: as_integer.h:226
AS_EXTERN int as_arraylist_trim(as_arraylist *list, uint32_t index)
static int as_arraylist_append_map(as_arraylist *list, as_map *value)
Definition: as_arraylist.h:922
AS_EXTERN as_val * as_arraylist_get(const as_arraylist *list, uint32_t index)
AS_EXTERN int as_arraylist_prepend_int64(as_arraylist *list, int64_t value)
AS_EXTERN int as_arraylist_append_double(as_arraylist *list, double value)
AS_EXTERN int as_arraylist_insert_double(as_arraylist *list, uint32_t index, double value)
static int as_arraylist_set_bytes(as_arraylist *list, uint32_t index, as_bytes *value)
Definition: as_arraylist.h:593
static as_bytes * as_arraylist_get_bytes(const as_arraylist *list, uint32_t index)
Definition: as_arraylist.h:437
AS_EXTERN uint32_t as_arraylist_hashcode(const as_arraylist *list)
Definition: as_map.h:61
static int as_arraylist_prepend_as_double(as_arraylist *list, as_double *value)
static int as_arraylist_prepend_integer(as_arraylist *list, as_integer *value)
Definition: as_arraylist.h:989
static int as_arraylist_set_map(as_arraylist *list, uint32_t index, as_map *value)
Definition: as_arraylist.h:625
static as_double * as_double_fromval(const as_val *value)
Definition: as_double.h:225
AS_EXTERN int as_arraylist_prepend_double(as_arraylist *list, double value)
AS_EXTERN char * as_arraylist_get_str(const as_arraylist *list, uint32_t index)
AS_EXTERN int as_arraylist_append(as_arraylist *list, as_val *value)
static as_double * as_arraylist_get_as_double(const as_arraylist *list, uint32_t index)
Definition: as_arraylist.h:407
AS_EXTERN as_arraylist * as_arraylist_take(const as_arraylist *list, uint32_t n)
Definition: as_val.h:61
bool(* as_list_foreach_callback)(as_val *value, void *udata)
Definition: as_list.h:50
AS_EXTERN int as_arraylist_set(as_arraylist *list, uint32_t index, as_val *value)
AS_EXTERN void as_arraylist_destroy(as_arraylist *list)
static int as_arraylist_prepend_bytes(as_arraylist *list, as_bytes *value)
AS_EXTERN int as_arraylist_insert(as_arraylist *list, uint32_t index, as_val *value)
#define AS_EXTERN
Definition: as_std.h:25
static int as_arraylist_prepend_string(as_arraylist *list, as_string *value)
AS_EXTERN int as_arraylist_append_str(as_arraylist *list, const char *value)
static int as_arraylist_insert_map(as_arraylist *list, uint32_t index, as_map *value)
Definition: as_arraylist.h:780
static int as_arraylist_prepend_list(as_arraylist *list, as_list *value)
uint32_t capacity
Definition: as_arraylist.h:113
AS_EXTERN int as_arraylist_prepend(as_arraylist *list, as_val *value)
AS_EXTERN int64_t as_arraylist_get_int64(const as_arraylist *list, uint32_t index)
AS_EXTERN int as_arraylist_append_int64(as_arraylist *list, int64_t value)
AS_EXTERN int as_arraylist_set_str(as_arraylist *list, uint32_t index, const char *value)
static int as_arraylist_set_string(as_arraylist *list, uint32_t index, as_string *value)
Definition: as_arraylist.h:577
static int as_arraylist_set_integer(as_arraylist *list, uint32_t index, as_integer *value)
Definition: as_arraylist.h:545
static int as_arraylist_insert_list(as_arraylist *list, uint32_t index, as_list *value)
Definition: as_arraylist.h:764
AS_EXTERN int as_arraylist_insert_int64(as_arraylist *list, uint32_t index, int64_t value)
static int as_arraylist_insert_as_double(as_arraylist *list, uint32_t index, as_double *value)
Definition: as_arraylist.h:716
AS_EXTERN as_arraylist * as_arraylist_tail(const as_arraylist *list)
AS_EXTERN int as_arraylist_remove(as_arraylist *list, uint32_t index)
static as_string * as_arraylist_get_string(const as_arraylist *list, uint32_t index)
Definition: as_arraylist.h:422
static as_bytes * as_bytes_fromval(const as_val *v)
Definition: as_bytes.h:977
as_arraylist_status
Definition: as_arraylist.h:136
AS_EXTERN uint32_t as_arraylist_size(const as_arraylist *list)
AS_EXTERN int as_arraylist_insert_str(as_arraylist *list, uint32_t index, const char *value)
static as_integer * as_arraylist_get_integer(const as_arraylist *list, uint32_t index)
Definition: as_arraylist.h:392
AS_EXTERN as_arraylist * as_arraylist_init(as_arraylist *list, uint32_t capacity, uint32_t block_size)
AS_EXTERN as_val * as_arraylist_head(const as_arraylist *list)
static int as_arraylist_prepend_map(as_arraylist *list, as_map *value)
static as_string * as_string_fromval(const as_val *v)
Definition: as_string.h:291
static int as_arraylist_insert_integer(as_arraylist *list, uint32_t index, as_integer *value)
Definition: as_arraylist.h:700
static as_map * as_arraylist_get_map(const as_arraylist *list, uint32_t index)
Definition: as_arraylist.h:467
uint32_t block_size
Definition: as_arraylist.h:108
uint32_t size
Definition: as_arraylist.h:118
static as_list * as_list_fromval(as_val *v)
Definition: as_list.h:1464
AS_EXTERN double as_arraylist_get_double(const as_arraylist *list, uint32_t index)
static int as_arraylist_append_integer(as_arraylist *list, as_integer *value)
Definition: as_arraylist.h:847
AS_EXTERN as_arraylist * as_arraylist_drop(const as_arraylist *list, uint32_t n)
static int as_arraylist_insert_bytes(as_arraylist *list, uint32_t index, as_bytes *value)
Definition: as_arraylist.h:748
AS_EXTERN as_arraylist * as_arraylist_new(uint32_t capacity, uint32_t block_size)
AS_EXTERN int as_arraylist_concat(as_arraylist *list, const as_arraylist *list2)
static int as_arraylist_append_string(as_arraylist *list, as_string *value)
Definition: as_arraylist.h:877
static int as_arraylist_append_list(as_arraylist *list, as_list *value)
Definition: as_arraylist.h:907
static as_map * as_map_fromval(const as_val *val)
Definition: as_map.h:424
static int as_arraylist_append_bytes(as_arraylist *list, as_bytes *value)
Definition: as_arraylist.h:892
static int as_arraylist_append_as_double(as_arraylist *list, as_double *value)
Definition: as_arraylist.h:862
static int as_arraylist_set_list(as_arraylist *list, uint32_t index, as_list *value)
Definition: as_arraylist.h:609
AS_EXTERN int as_arraylist_set_double(as_arraylist *list, uint32_t index, double value)
static int as_arraylist_set_as_double(as_arraylist *list, uint32_t index, as_double *value)
Definition: as_arraylist.h:561
static as_list * as_arraylist_get_list(const as_arraylist *list, uint32_t index)
Definition: as_arraylist.h:452
AS_EXTERN int as_arraylist_set_int64(as_arraylist *list, uint32_t index, int64_t value)
as_val ** elements
Definition: as_arraylist.h:123
AS_EXTERN bool as_arraylist_foreach(const as_arraylist *list, as_list_foreach_callback callback, void *udata)