CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
Slicing, Cloning & Merging

Macros

#define saSlice(out, src, start, end)   _saSlice(SAHANDLE(out), SAREF(src), start, end)
 
#define saClone(out, src)   _saSlice(SAHANDLE(out), SAREF(src), 0, 0)
 
#define saMerge(out, ...)
 
#define saMergeF(out, flags, ...)
 

Detailed Description

Macro Definition Documentation

◆ saClone

#define saClone (   out,
  src 
)    _saSlice(SAHANDLE(out), SAREF(src), 0, 0)

void saClone(sa_type *out, sa_type src)

Creates a deep copy of the entire array

This is a convenience wrapper around saSlice that copies all elements. All elements are deep copied into the new array.

Parameters
outPointer to uninitialized array to receive the clone
srcSource array to clone (passed by value)

Example:

sa_string clone;
saClone(&clone, original);
// modify clone without affecting original
saDestroy(&clone);
#define saClone(out, src)
Definition sarray.h:776
#define saDestroy(handle)
Definition sarray.h:348

Definition at line 776 of file sarray.h.

◆ saMerge

#define saMerge (   out,
  ... 
)
Value:
_saMerge(SAHANDLE(out), \
sizeof((sa_ref[]) { __VA_ARGS__ }) / sizeof(sa_ref), \
(sa_ref[]) { __VA_ARGS__ }, \
0)

void saMerge(sa_type *out, sa_type array1, sa_type array2, ...)

Creates a new array by concatenating multiple source arrays

All elements from all source arrays are deep copied into the new array in order. Source arrays must all be the same element type. The output inherits flags from the first source array.

Parameters
outPointer to uninitialized array to receive the merged result
...Variable number of source arrays to merge (passed by value)

Example:

sa_int32 merged;
saMerge(&merged, arr1, arr2, arr3); // Concatenate three arrays
saDestroy(&merged);
#define saMerge(out,...)
Definition sarray.h:798

Definition at line 798 of file sarray.h.

◆ saMergeF

#define saMergeF (   out,
  flags,
  ... 
)
Value:
_saMerge(SAHANDLE(out), \
sizeof((sa_ref[]) { __VA_ARGS__ }) / sizeof(sa_ref), \
(sa_ref[]) { __VA_ARGS__ }, \
flags)

void saMergeF(sa_type *out, flags_t flags, sa_type array1, sa_type array2, ...)

Creates a new array by merging multiple source arrays with specified flags

Like saMerge but allows specifying flags. If SA_Unique is set, duplicate elements are not inserted (requires element type to support equality comparison).

Parameters
outPointer to uninitialized array to receive the merged result
flagsMerge flags (e.g., SA_Unique to exclude duplicates)
...Variable number of source arrays to merge (passed by value)

Example:

sa_int32 unique;
saMergeF(&unique, SA_Unique, arr1, arr2); // Merge without duplicates
saDestroy(&unique);
#define saMergeF(out, flags,...)
Definition sarray.h:821
@ SA_Unique
Definition sarray.h:174

Definition at line 821 of file sarray.h.

◆ saSlice

#define saSlice (   out,
  src,
  start,
  end 
)    _saSlice(SAHANDLE(out), SAREF(src), start, end)

void saSlice(sa_type *out, sa_type src, int32 start, int32 end)

Creates a new array containing a slice (subrange) of the source array

All elements in the range are deep copied into the new array. The source array is unmodified. Negative indices count from the end of the array.

Parameters
outPointer to uninitialized array to receive the slice
srcSource array to slice from (passed by value)
startStarting index (inclusive), negative counts from end
endEnding index (exclusive), 0 means to end of array, negative counts from end

Example:

sa_int32 slice;
saSlice(&slice, arr, 5, 10); // Elements 5-9
saSlice(&slice, arr, -5, 0); // Last 5 elements
saSlice(&slice, arr, 0, -5); // All but last 5 elements
saDestroy(&slice);
#define saSlice(out, src, start, end)
Definition sarray.h:757

Definition at line 757 of file sarray.h.