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-2015 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 
18 #pragma once
19 
20 #include <aerospike/as_integer.h>
21 #include <aerospike/as_string.h>
22 #include <aerospike/as_bytes.h>
23 #include <aerospike/as_list.h>
24 #include <aerospike/as_map.h>
25 #include <aerospike/as_val.h>
26 
27 #include <stdbool.h>
28 #include <stdint.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /******************************************************************************
35  * TYPES
36  *****************************************************************************/
37 
38 /**
39  * An dynamic array implementation for as_list.
40  *
41  * as_arryalist can either be initialize on the stack or the heap.
42  *
43  * For stack allocation, you have two choices:
44  * - `as_arraylist_init()` - uses `cf_malloc()` to initialize the internal storage
45  * on the heap.
46  * - `as_arraylist_inita()` - uses `alloca()` to initialize the internal storage
47  * on the stack.
48  *
49  * The key differences between the two is `as_arraylist_inita()` can't be
50  * dynamically resized and is solely on the stack.
51  *
52  * The following is using a `as_arraylist_inita()`:
53  * ~~~~~~~~~~{.c}
54  * as_arraylist list;
55  * as_arraylist_inita(&list, 2);
56  * ~~~~~~~~~~
57  *
58  * You will notice that the code is quite similar to `as_arraylist_init()`:
59  * ~~~~~~~~~~{.c}
60  * as_arraylist list;
61  * as_arraylist_init(&list, 2, 0);
62  * ~~~~~~~~~~
63  *
64  * If you need a new heap allocated list, then use `as_arraylist_new()`:
65  *
66  * ~~~~~~~~~~{.c}
67  * as_arraylist * list = as_arraylist_new(2, 0);
68  * ~~~~~~~~~~
69  *
70  * When you are finished using the list, then you should release the list and
71  * associated resources, using `as_arraylist_destroy()`:
72  *
73  * ~~~~~~~~~~{.c}
74  * as_arraylist_destroy(list);
75  * ~~~~~~~~~~
76  *
77  *
78  * The `as_arraylist` is a subtype of `as_list`. This allows you to
79  * alternatively use `as_list` functions, by typecasting `as_arraylist` to
80  * `as_list`.
81  *
82  * ~~~~~~~~~~{.c}
83  * as_arraylist list;
84  * as_list * l = (as_list *) as_arraylist_init(&list, 3, 0);
85  * as_list_append_int64(l, 1);
86  * as_list_append_int64(l, 2);
87  * as_list_append_int64(l, 3);
88  * as_list_destroy(l);
89  * ~~~~~~~~~~
90  *
91  * Each of the `as_list` functions proxy to the `as_arraylist` functions.
92  * So, calling `as_list_destroy()` is equivalent to calling
93  * `as_arraylist_destroy()`.
94  *
95  * @extends as_list
96  * @ingroup aerospike_t
97  */
98 typedef struct as_arraylist_s {
99 
100  /**
101  * @private
102  * as_arraylist is an as_list.
103  * You can cast as_arraylist to as_list.
104  */
106 
107  /**
108  * Number of elements to add, when capacity is reached.
109  * If 0 (zero), then capacity can't be expanded.
110  */
111  uint32_t block_size;
112 
113  /**
114  * The total number elements allocated.
115  */
116  uint32_t capacity;
117 
118  /**
119  * The number of elements used.
120  */
121  uint32_t size;
122 
123  /**
124  * The elements of the list.
125  */
127 
128  /**
129  * If true, then as_arraylist.elements will be freed when
130  * as_arraylist_destroy() is called.
131  */
132  bool free;
133 
134 } as_arraylist;
135 
136 /**
137  * Status codes for various as_arraylist operations.
138  */
139 typedef enum as_arraylist_status_e {
140 
141  /**
142  * Normal operation.
143  */
145 
146  /**
147  * Unable to expand capacity, because cf_realloc() failed.
148  */
150 
151  /**
152  * Unable to expand capacity, because as_arraylist.block_size is 0.
153  */
155 
156  /**
157  * Illegal array index.
158  */
160 
162 
163 /******************************************************************************
164  * MACROS
165  ******************************************************************************/
166 
167 /**
168  * Initialize a stack allocated as_arraylist, with element storage on
169  * the stack.
170  *
171  * This differs from as_arraylist_init(), in that as_arraylist_init()
172  * allocates element storage on the heap.
173  *
174  * @param __list The as_list to initialize
175  * @param __n The number of elements to allocate to the list.
176  *
177  * @return On success, the initialize list. Otherwise NULL.
178  * @relatesalso as_arraylist
179  */
180 #define as_arraylist_inita(__list, __n)\
181  as_arraylist_init((__list), 0, 0);\
182  (__list)->free = false;\
183  (__list)->capacity = __n;\
184  (__list)->size = 0;\
185  (__list)->elements = (as_val **) alloca(sizeof(as_val *) * __n);
186 
187 /*******************************************************************************
188  * INSTANCE FUNCTIONS
189  ******************************************************************************/
190 
191 /**
192  * Initialize a stack allocated as_arraylist, with element storage on the
193  * heap.
194  *
195  * This differs from as_arraylist_inita(), in that as_arraylist_inita()
196  * allocates element storage on the stack.
197  *
198  * @param list The as_list to initialize
199  * @param capacity The number of elements to allocate to the list.
200  * @param block_size The number of elements to grow the list by, when the
201  * capacity has been reached.
202  *
203  * @return On success, the initialize list. Otherwise NULL.
204  * @relatesalso as_arraylist
205  */
206 as_arraylist * as_arraylist_init(as_arraylist * list, uint32_t capacity, uint32_t block_size);
207 
208 /**
209  * Create and initialize a heap allocated list as as_arraylist.
210  *
211  * @param capacity The number of elements to allocate to the list.
212  * @param block_size The number of elements to grow the list by, when the
213  * capacity has been reached.
214  *
215  * @return On success, the new list. Otherwise NULL.
216  * @relatesalso as_arraylist
217  */
218 as_arraylist * as_arraylist_new(uint32_t capacity, uint32_t block_size);
219 
220 /**
221  * Destoy the list and release resources.
222  *
223  * @param list The list to destroy.
224  * @relatesalso as_arraylist
225  */
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 uint32_t as_arraylist_hashcode(const as_arraylist * list);
241 
242 /**
243  * The number of elements in the list.
244  *
245  * @param list The list.
246  *
247  * @return The number of elements in the list.
248  * @relatesalso as_arraylist
249  */
250 uint32_t as_arraylist_size(const as_arraylist * list);
251 
252 /*******************************************************************************
253  * ACCESSOR AND MODIFIER FUNCTIONS
254  ******************************************************************************/
255 
256 /**
257  * Append all elements of list2, in order, to list. No new list object is
258  * created.
259  *
260  * @param list The list to append to.
261  * @param list2 The list from which to append.
262  *
263  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
264  * @relatesalso as_arraylist
265  */
266 int as_arraylist_concat(as_arraylist * list, const as_arraylist * list2);
267 
268 /**
269  * Delete (and destroy) all elements at and beyond specified index. Capacity is
270  * not reduced.
271  *
272  * @param list The list to trim.
273  * @param index The index from which to trim.
274  *
275  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
276  * @relatesalso as_arraylist
277  */
278 int as_arraylist_trim(as_arraylist * list, uint32_t index);
279 
280 /**
281  * Get the first element of the list.
282  *
283  * @param list The list to get the first element from.
284  *
285  * @return The first element of the list. Otherwise NULL.
286  * @relatesalso as_arraylist
287  */
288 as_val * as_arraylist_head(const as_arraylist * list);
289 
290 /**
291  * Returns a new list containing all elements other than the head
292  *
293  * @param list The list to get the elements from.
294  *
295  * @return A new list of all elements after the first element.
296  * @relatesalso as_arraylist
297  */
299 
300 /**
301  * Return a new list with the first n elements removed.
302  *
303  * @param list The list.
304  * @param n The number of elements to remove.
305  *
306  * @return A new list of all elements after the first n elements.
307  * @relatesalso as_arraylist
308  */
309 as_arraylist * as_arraylist_drop(const as_arraylist * list, uint32_t n);
310 
311 /**
312  * Return a new list containing the first n elements.
313  *
314  * @param list The list.
315  * @param n The number of elements to take.
316  *
317  * @return A new list of the first n elements.
318  * @relatesalso as_arraylist
319  */
320 as_arraylist * as_arraylist_take(const as_arraylist * list, uint32_t n);
321 
322 /******************************************************************************
323  * GET FUNCTIONS
324  ******************************************************************************/
325 
326 /**
327  * Return the value at the specified index.
328  *
329  * @param list The list.
330  * @param index The index of the element.
331  *
332  * @return The value at given index, if it exists. Otherwise NULL.
333  * @relatesalso as_arraylist
334  */
335 as_val * as_arraylist_get(const as_arraylist * list, uint32_t index);
336 
337 /**
338  * Return an int64_t value at the specified index of the list.
339  *
340  * @param list The list.
341  * @param index The index of the element.
342  *
343  * @return The value at given index, if it exists. Otherwise NULL.
344  * @relatesalso as_arraylist
345  */
346 int64_t as_arraylist_get_int64(const as_arraylist * list, uint32_t index);
347 
348 /**
349  * Return a NULL-terminated value at the specified index of the list.
350  *
351  * @param list The list.
352  * @param index The index of the element.
353  *
354  * @return The value at given index, if it exists. Otherwise NULL.
355  * @relatesalso as_arraylist
356  */
357 char * as_arraylist_get_str(const as_arraylist * list, uint32_t index);
358 
359 /**
360  * Return an as_integer value at the specified index of the list.
361  *
362  * @param list The list.
363  * @param index The index of the element.
364  *
365  * @return The value at given index, if it exists. Otherwise NULL.
366  * @relatesalso as_arraylist
367  */
368 static inline as_integer * as_arraylist_get_integer(const as_arraylist * list, uint32_t index)
369 {
370  return as_integer_fromval(as_arraylist_get(list, index));
371 }
372 
373 /**
374  * Return an as_string value at the specified index of the list.
375  *
376  * @param list The list.
377  * @param index The index of the element.
378  *
379  * @return The value at given index, if it exists. Otherwise NULL.
380  * @relatesalso as_arraylist
381  */
382 static inline as_string * as_arraylist_get_string(const as_arraylist * list, uint32_t index)
383 {
384  return as_string_fromval(as_arraylist_get(list, index));
385 }
386 
387 /**
388  * Return an as_bytes value at the specified index of the list.
389  *
390  * @param list The list.
391  * @param index The index of the element.
392  *
393  * @return The value at given index, if it exists. Otherwise NULL.
394  * @relatesalso as_arraylist
395  */
396 static inline as_bytes * as_arraylist_get_bytes(const as_arraylist * list, uint32_t index)
397 {
398  return as_bytes_fromval(as_arraylist_get(list, index));
399 }
400 
401 /**
402  * Return an as_list value at the specified index of the list.
403  *
404  * @param list The list.
405  * @param index The index of the element.
406  *
407  * @return The value at given index, if it exists. Otherwise NULL.
408  * @relatesalso as_arraylist
409  */
410 static inline as_list * as_arraylist_get_list(const as_arraylist * list, uint32_t index)
411 {
412  return as_list_fromval(as_arraylist_get(list, index));
413 }
414 
415 /**
416  * Return an as_map value at the specified index of the list.
417  *
418  * @param list The list.
419  * @param index The index of the element.
420  *
421  * @return The value at given index, if it exists. Otherwise NULL.
422  * @relatesalso as_arraylist
423  */
424 static inline as_map * as_arraylist_get_map(const as_arraylist * list, uint32_t index)
425 {
426  return as_map_fromval(as_arraylist_get(list, index));
427 }
428 
429 /******************************************************************************
430  * SET FUNCTIONS
431  ******************************************************************************/
432 
433 /**
434  * Set a value at the specified index of the list.
435  *
436  * Notice that in order to maintain proper object/memory management, we
437  * just first destroy (as_val_destroy()) the old object at element position(i)
438  * before assigning the new element. Also note that the object at element
439  * position (i) is assumed to exist, so all element positions must be
440  * appropriately initialized to zero.
441  *
442  * @param list The list.
443  * @param index Position in the list.
444  * @param value The value to set at the given index.
445  *
446  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
447  * @relatesalso as_arraylist
448  */
449 int as_arraylist_set(as_arraylist * list, uint32_t index, as_val * value);
450 
451 /**
452  * Set an int64_t value at the specified index of the list.
453  *
454  * @param list The list.
455  * @param index Position in the list.
456  * @param value The value to set at the given index.
457  *
458  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
459  * @relatesalso as_arraylist
460  */
461 int as_arraylist_set_int64(as_arraylist * list, uint32_t index, int64_t value);
462 
463 /**
464  * Set a NULL-terminated string value at the specified index of the list.
465  *
466  * @param list The list.
467  * @param index Position in the list.
468  * @param value The value to set at the given index.
469  *
470  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
471  * @relatesalso as_arraylist
472  */
473 int as_arraylist_set_str(as_arraylist * list, uint32_t index, const char * value);
474 
475 /**
476  * Set an as_integer value at the specified index of the list.
477  *
478  * @param list The list.
479  * @param index Position in the list.
480  * @param value The value to set at the given index.
481  *
482  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
483  * @relatesalso as_arraylist
484  */
485 static inline int as_arraylist_set_integer(as_arraylist * list, uint32_t index, as_integer * value)
486 {
487  return as_arraylist_set(list, index, (as_val *) value);
488 }
489 
490 /**
491  * Set an as_string value at the specified index of the list.
492  *
493  * @param list The list.
494  * @param index Position in the list.
495  * @param value The value to set at the given index.
496  *
497  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
498  * @relatesalso as_arraylist
499  */
500 static inline int as_arraylist_set_string(as_arraylist * list, uint32_t index, as_string * value)
501 {
502  return as_arraylist_set(list, index, (as_val *) value);
503 }
504 
505 /**
506  * Set an as_bytes value at the specified index of the list.
507  *
508  * @param list The list.
509  * @param index Position in the list.
510  * @param value The value to set at the given index.
511  *
512  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
513  * @relatesalso as_arraylist
514  */
515 static inline int as_arraylist_set_bytes(as_arraylist * list, uint32_t index, as_bytes * value)
516 {
517  return as_arraylist_set(list, index, (as_val *) value);
518 }
519 
520 /**
521  * Set an as_list value at the specified index of the list.
522  *
523  * @param list The list.
524  * @param index Position in the list.
525  * @param value The value to set at the given index.
526  *
527  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
528  * @relatesalso as_arraylist
529  */
530 static inline int as_arraylist_set_list(as_arraylist * list, uint32_t index, as_list * value)
531 {
532  return as_arraylist_set(list, index, (as_val *) value);
533 }
534 
535 /**
536  * Set an as_map value at the specified index of the list.
537  *
538  * @param list The list.
539  * @param index Position in the list.
540  * @param value The value to set at the given index.
541  *
542  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
543  * @relatesalso as_arraylist
544  */
545 static inline int as_arraylist_set_map(as_arraylist * list, uint32_t index, as_map * value)
546 {
547  return as_arraylist_set(list, index, (as_val *) value);
548 }
549 
550 /******************************************************************************
551  * INSERT FUNCTIONS
552  ******************************************************************************/
553 
554 /**
555  * Insert a value at the specified index of the list.
556  *
557  * Any elements at and beyond specified index will be shifted so their indexes
558  * increase by 1. It's ok to insert beyond the current end of the list.
559  *
560  * @param list The list.
561  * @param index Position in the list.
562  * @param value The value to insert at the given index.
563  *
564  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
565  * @relatesalso as_arraylist
566  */
567 int as_arraylist_insert(as_arraylist * list, uint32_t index, as_val * value);
568 
569 /**
570  * Insert an int64_t value at the specified index of the list.
571  *
572  * @param list The list.
573  * @param index Position in the list.
574  * @param value The value to insert at the given index.
575  *
576  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
577  * @relatesalso as_arraylist
578  */
579 int as_arraylist_insert_int64(as_arraylist * list, uint32_t index, int64_t value);
580 
581 /**
582  * Insert a NULL-terminated string value at the specified index of the list.
583  *
584  * @param list The list.
585  * @param index Position in the list.
586  * @param value The value to insert at the given index.
587  *
588  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
589  * @relatesalso as_arraylist
590  */
591 int as_arraylist_insert_str(as_arraylist * list, uint32_t index, const char * value);
592 
593 /**
594  * Insert an as_integer value at the specified index of the list.
595  *
596  * @param list The list.
597  * @param index Position in the list.
598  * @param value The value to insert at the given index.
599  *
600  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
601  * @relatesalso as_arraylist
602  */
603 static inline int as_arraylist_insert_integer(as_arraylist * list, uint32_t index, as_integer * value)
604 {
605  return as_arraylist_insert(list, index, (as_val *) value);
606 }
607 
608 /**
609  * Insert an as_string value at the specified index of the list.
610  *
611  * @param list The list.
612  * @param index Position in the list.
613  * @param value The value to insert at the given index.
614  *
615  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
616  * @relatesalso as_arraylist
617  */
618 static inline int as_arraylist_insert_string(as_arraylist * list, uint32_t index, as_string * value)
619 {
620  return as_arraylist_insert(list, index, (as_val *) value);
621 }
622 
623 /**
624  * Insert an as_bytes value at the specified index of the list.
625  *
626  * @param list The list.
627  * @param index Position in the list.
628  * @param value The value to insert at the given index.
629  *
630  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
631  * @relatesalso as_arraylist
632  */
633 static inline int as_arraylist_insert_bytes(as_arraylist * list, uint32_t index, as_bytes * value)
634 {
635  return as_arraylist_insert(list, index, (as_val *) value);
636 }
637 
638 /**
639  * Insert an as_list value at the specified index of the list.
640  *
641  * @param list The list.
642  * @param index Position in the list.
643  * @param value The value to insert at the given index.
644  *
645  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
646  * @relatesalso as_arraylist
647  */
648 static inline int as_arraylist_insert_list(as_arraylist * list, uint32_t index, as_list * value)
649 {
650  return as_arraylist_insert(list, index, (as_val *) value);
651 }
652 
653 /**
654  * Insert an as_map value at the specified index of the list.
655  *
656  * @param list The list.
657  * @param index Position in the list.
658  * @param value The value to insert at the given index.
659  *
660  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
661  * @relatesalso as_arraylist
662  */
663 static inline int as_arraylist_insert_map(as_arraylist * list, uint32_t index, as_map * value)
664 {
665  return as_arraylist_insert(list, index, (as_val *) value);
666 }
667 
668 /******************************************************************************
669  * APPEND FUNCTIONS
670  ******************************************************************************/
671 
672 /**
673  * Add the value to the end of the list.
674  *
675  * @param list The list.
676  * @param value The value to prepend.
677  *
678  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
679  * @relatesalso as_arraylist
680  */
681 int as_arraylist_append(as_arraylist * list, as_val * value);
682 
683 /**
684  * Add an int64_t to the end of the list.
685  *
686  * @param list The list.
687  * @param value The value to prepend.
688  *
689  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
690  * @relatesalso as_arraylist
691  */
692 int as_arraylist_append_int64(as_arraylist * list, int64_t value);
693 
694 /**
695  * Add a NULL-terminated string to the end of the list.
696  *
697  * @param list The list.
698  * @param value The value to prepend.
699  *
700  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
701  * @relatesalso as_arraylist
702  */
703 int as_arraylist_append_str(as_arraylist * list, const char * value);
704 
705 /**
706  * Add an as_integer to the end of the list.
707  *
708  * @param list The list.
709  * @param value The value to prepend.
710  *
711  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
712  * @relatesalso as_arraylist
713  */
714 static inline int as_arraylist_append_integer(as_arraylist * list, as_integer * value)
715 {
716  return as_arraylist_append(list, (as_val *) value);
717 }
718 
719 /**
720  * Add an as_string to the end of the list.
721  *
722  * @param list The list.
723  * @param value The value to prepend.
724  *
725  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
726  * @relatesalso as_arraylist
727  */
728 static inline int as_arraylist_append_string(as_arraylist * list, as_string * value)
729 {
730  return as_arraylist_append(list, (as_val *) value);
731 }
732 
733 /**
734  * Add an as_bytes to the end of the list.
735  *
736  * @param list The list.
737  * @param value The value to prepend.
738  *
739  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
740  * @relatesalso as_arraylist
741  */
742 static inline int as_arraylist_append_bytes(as_arraylist * list, as_bytes * value)
743 {
744  return as_arraylist_append(list, (as_val *) value);
745 }
746 
747 /**
748  * Add an as_list to the end of the list.
749  *
750  * @param list The list.
751  * @param value The value to prepend.
752  *
753  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
754  * @relatesalso as_arraylist
755  */
756 static inline int as_arraylist_append_list(as_arraylist * list, as_list * value)
757 {
758  return as_arraylist_append(list, (as_val *) value);
759 }
760 
761 /**
762  * Add an as_map to the end of the list.
763  *
764  * @param list The list.
765  * @param value The value to prepend.
766  *
767  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
768  * @relatesalso as_arraylist
769  */
770 static inline int as_arraylist_append_map(as_arraylist * list, as_map * value)
771 {
772  return as_arraylist_append(list, (as_val *) value);
773 }
774 
775 /******************************************************************************
776  * PREPEND FUNCTIONS
777  ******************************************************************************/
778 
779 /**
780  * Add the value to the beginning of the list.
781  *
782  * @param list The list.
783  * @param value The value to prepend.
784  *
785  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
786  * @relatesalso as_arraylist
787  */
788 int as_arraylist_prepend(as_arraylist * list, as_val * value);
789 
790 /**
791  * Add an int64_t to the beginning of the list.
792  *
793  * @param list The list.
794  * @param value The value to prepend.
795  *
796  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
797  * @relatesalso as_arraylist
798  */
799 int as_arraylist_prepend_int64(as_arraylist * list, int64_t value);
800 
801 /**
802  * Add a NULL-terminated string to the beginning 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 int as_arraylist_prepend_str(as_arraylist * list, const char * value);
811 
812 /**
813  * Add an as_integer to the beginning of the list.
814  *
815  * @param list The list.
816  * @param value The value to prepend.
817  *
818  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
819  * @relatesalso as_arraylist
820  */
821 static inline int as_arraylist_prepend_integer(as_arraylist * list, as_integer * value)
822 {
823  return as_arraylist_prepend(list, (as_val *) value);
824 }
825 
826 /**
827  * Add an as_string to the beginning of the list.
828  *
829  * @param list The list.
830  * @param value The value to prepend.
831  *
832  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
833  * @relatesalso as_arraylist
834  */
835 static inline int as_arraylist_prepend_string(as_arraylist * list, as_string * value)
836 {
837  return as_arraylist_prepend(list, (as_val *) value);
838 }
839 
840 /**
841  * Add an as_bytes to the beginning of the list.
842  *
843  * @param list The list.
844  * @param value The value to prepend.
845  *
846  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
847  * @relatesalso as_arraylist
848  */
849 static inline int as_arraylist_prepend_bytes(as_arraylist * list, as_bytes * value)
850 {
851  return as_arraylist_prepend(list, (as_val *) value);
852 }
853 
854 /**
855  * Add an as_list to the beginning of the list.
856  *
857  * @param list The list.
858  * @param value The value to prepend.
859  *
860  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
861  * @relatesalso as_arraylist
862  */
863 static inline int as_arraylist_prepend_list(as_arraylist * list, as_list * value)
864 {
865  return as_arraylist_prepend(list, (as_val *) value);
866 }
867 
868 /**
869  * Add an as_map to the beginning of the list.
870  *
871  * @param list The list.
872  * @param value The value to prepend.
873  *
874  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
875  * @relatesalso as_arraylist
876  */
877 static inline int as_arraylist_prepend_map(as_arraylist * list, as_map * value)
878 {
879  return as_arraylist_prepend(list, (as_val *) value);
880 }
881 
882 /*******************************************************************************
883  * REMOVE FUNCTION
884  ******************************************************************************/
885 
886 /**
887  * Remove element at specified index.
888  *
889  * Any elements beyond specified index will be shifted so their indexes
890  * decrease by 1. The element at specified index will be destroyed.
891  *
892  * @param list The list.
893  * @param index The index of the element to remove.
894  *
895  * @return AS_ARRAYLIST_OK on success. Otherwise an error occurred.
896  * @relatesalso as_arraylist
897  */
898 int as_arraylist_remove(as_arraylist * list, uint32_t index);
899 
900 /******************************************************************************
901  * ITERATION FUNCTIONS
902  ******************************************************************************/
903 
904 /**
905  * Call the callback function for each element in the list.
906  *
907  * @param list The list to iterate.
908  * @param callback The function to call for each element in the list.
909  * @param udata User-data to be sent to the callback.
910  *
911  * @return true if iteration completes fully. false if iteration was aborted.
912  *
913  * @relatesalso as_arraylist
914  */
915 bool as_arraylist_foreach(const as_arraylist * list, as_list_foreach_callback callback, void * udata);
916 
917 #ifdef __cplusplus
918 } // end extern "C"
919 #endif
static int as_arraylist_insert_string(as_arraylist *list, uint32_t index, as_string *value)
Definition: as_arraylist.h:618
static as_integer * as_integer_fromval(const as_val *v)
Definition: as_integer.h:234
uint32_t as_arraylist_size(const as_arraylist *list)
static int as_arraylist_append_map(as_arraylist *list, as_map *value)
Definition: as_arraylist.h:770
int as_arraylist_insert_int64(as_arraylist *list, uint32_t index, int64_t value)
static int as_arraylist_set_bytes(as_arraylist *list, uint32_t index, as_bytes *value)
Definition: as_arraylist.h:515
as_val * as_arraylist_head(const as_arraylist *list)
static as_bytes * as_arraylist_get_bytes(const as_arraylist *list, uint32_t index)
Definition: as_arraylist.h:396
Definition: as_map.h:61
as_arraylist * as_arraylist_new(uint32_t capacity, uint32_t block_size)
static int as_arraylist_prepend_integer(as_arraylist *list, as_integer *value)
Definition: as_arraylist.h:821
static int as_arraylist_set_map(as_arraylist *list, uint32_t index, as_map *value)
Definition: as_arraylist.h:545
int as_arraylist_prepend_str(as_arraylist *list, const char *value)
int as_arraylist_append_int64(as_arraylist *list, int64_t value)
int as_arraylist_set_str(as_arraylist *list, uint32_t index, const char *value)
as_arraylist * as_arraylist_tail(const as_arraylist *list)
Definition: as_val.h:55
bool(* as_list_foreach_callback)(as_val *value, void *udata)
Definition: as_list.h:51
int as_arraylist_prepend_int64(as_arraylist *list, int64_t value)
static int as_arraylist_prepend_bytes(as_arraylist *list, as_bytes *value)
Definition: as_arraylist.h:849
static int as_arraylist_prepend_string(as_arraylist *list, as_string *value)
Definition: as_arraylist.h:835
static int as_arraylist_insert_map(as_arraylist *list, uint32_t index, as_map *value)
Definition: as_arraylist.h:663
static int as_arraylist_prepend_list(as_arraylist *list, as_list *value)
Definition: as_arraylist.h:863
char * as_arraylist_get_str(const as_arraylist *list, uint32_t index)
int as_arraylist_append(as_arraylist *list, as_val *value)
uint32_t capacity
Definition: as_arraylist.h:116
int as_arraylist_prepend(as_arraylist *list, as_val *value)
int as_arraylist_concat(as_arraylist *list, const as_arraylist *list2)
static int as_arraylist_set_string(as_arraylist *list, uint32_t index, as_string *value)
Definition: as_arraylist.h:500
as_arraylist * as_arraylist_init(as_arraylist *list, uint32_t capacity, uint32_t block_size)
static int as_arraylist_set_integer(as_arraylist *list, uint32_t index, as_integer *value)
Definition: as_arraylist.h:485
static int as_arraylist_insert_list(as_arraylist *list, uint32_t index, as_list *value)
Definition: as_arraylist.h:648
int as_arraylist_insert(as_arraylist *list, uint32_t index, as_val *value)
static as_string * as_arraylist_get_string(const as_arraylist *list, uint32_t index)
Definition: as_arraylist.h:382
int as_arraylist_remove(as_arraylist *list, uint32_t index)
uint32_t as_arraylist_hashcode(const as_arraylist *list)
int as_arraylist_insert_str(as_arraylist *list, uint32_t index, const char *value)
static as_bytes * as_bytes_fromval(const as_val *v)
Definition: as_bytes.h:915
as_arraylist_status
Definition: as_arraylist.h:139
static as_integer * as_arraylist_get_integer(const as_arraylist *list, uint32_t index)
Definition: as_arraylist.h:368
static int as_arraylist_prepend_map(as_arraylist *list, as_map *value)
Definition: as_arraylist.h:877
static as_string * as_string_fromval(const as_val *v)
Definition: as_string.h:296
static int as_arraylist_insert_integer(as_arraylist *list, uint32_t index, as_integer *value)
Definition: as_arraylist.h:603
static as_map * as_arraylist_get_map(const as_arraylist *list, uint32_t index)
Definition: as_arraylist.h:424
void as_arraylist_destroy(as_arraylist *list)
uint32_t block_size
Definition: as_arraylist.h:111
uint32_t size
Definition: as_arraylist.h:121
bool as_arraylist_foreach(const as_arraylist *list, as_list_foreach_callback callback, void *udata)
static as_list * as_list_fromval(as_val *v)
Definition: as_list.h:1272
as_arraylist * as_arraylist_drop(const as_arraylist *list, uint32_t n)
as_val * as_arraylist_get(const as_arraylist *list, uint32_t index)
static int as_arraylist_append_integer(as_arraylist *list, as_integer *value)
Definition: as_arraylist.h:714
static int as_arraylist_insert_bytes(as_arraylist *list, uint32_t index, as_bytes *value)
Definition: as_arraylist.h:633
int as_arraylist_set(as_arraylist *list, uint32_t index, as_val *value)
int as_arraylist_set_int64(as_arraylist *list, uint32_t index, int64_t value)
static int as_arraylist_append_string(as_arraylist *list, as_string *value)
Definition: as_arraylist.h:728
static int as_arraylist_append_list(as_arraylist *list, as_list *value)
Definition: as_arraylist.h:756
static as_map * as_map_fromval(const as_val *val)
Definition: as_map.h:406
static int as_arraylist_append_bytes(as_arraylist *list, as_bytes *value)
Definition: as_arraylist.h:742
static int as_arraylist_set_list(as_arraylist *list, uint32_t index, as_list *value)
Definition: as_arraylist.h:530
as_arraylist * as_arraylist_take(const as_arraylist *list, uint32_t n)
int64_t as_arraylist_get_int64(const as_arraylist *list, uint32_t index)
static as_list * as_arraylist_get_list(const as_arraylist *list, uint32_t index)
Definition: as_arraylist.h:410
int as_arraylist_trim(as_arraylist *list, uint32_t index)
int as_arraylist_append_str(as_arraylist *list, const char *value)
as_val ** elements
Definition: as_arraylist.h:126