Vectors
The growable arrays Open Graph's functions take and return: vectors of real numbers and their integer, Boolean, character and complex twins, and vectors of pointers.
112 entries: 109 functions and 3 types. Part of the Open Graph reference; All functions lists every entry on one page, with a filter. The badges say how each entry is checked.
Types
vector_ttype#
Unit tests
A growable array of reals; the template for the integer, bool, char, complex and pointer vectors.
typedef struct og_vector_t og_vector_t; struct og_vector_t { og_real_t *data; og_int_t size; og_int_t capacity; };
data[0 .. size - 1] are the elements and capacity is how many fit before the storage has to grow. OG_VECTOR(v)[i] (or the short form VECTOR(v)[i]) reads or writes element i directly, without checks.
The same template gives og_vector_int_t (og_int_t elements), og_vector_bool_t (og_bool_t), og_vector_char_t (char), og_vector_complex_t (og_complex_t) and og_vector_ptr_t (void *, plus an item destructor). Every function exists for each element type with the type in its name (og_vector_int_size, og_vector_complex_sum, ...) unless its entry says otherwise.
Initialise a vector with one of the init functions and release it with vector_destroy. A view (vector_view) borrows memory instead and must never be resized or destroyed. Helpers outside the template: og_vector_init_real, og_vector_init_int and og_vector_int_init_int build a vector from variadic arguments; og_vector_print and og_vector_fprint write the elements separated by spaces and a newline; OG_VECTOR_INIT_FINALLY (and its typed siblings) initialises a vector and registers it on the cleanup stack in one step.
- Checked
- The type and its int, bool, char, complex and ptr instantiations come from one include-template; python-igraph has no vector API, so the vector functions are checked by unit tests, independent verifiers' tests and a Python model.
- C name
og_vector_t- In notebooks
Og.Vector- igraph 1.0
igraph_vector_t- See also
vector_init,vector_destroy,vector_ptr_init
vector_list_ttype#
Unit tests
A growable list of real vectors that owns its items.
typedef struct og_vector_list_t og_vector_list_t; struct og_vector_list_t { og_vector_t *items; og_int_t size; og_int_t capacity; };
A vector is created when it enters the list and destroyed when it leaves, unless a function hands it to the caller (pop_back, remove, replace). og_vector_int_list_t is the same for integer vectors. The types are declared with the core containers because many public signatures use them; their functions (vector_list_init, vector_list_push_back, vector_list_get_ptr, vector_list_sort, ...) are documented with the containers area.
- Checked
- Provided with the containers (include/og/containers.h); unit tests in tests/containers.
- C name
og_vector_list_t- In notebooks
Og.VectorList- igraph 1.0
igraph_vector_list_t- See also
vector_t,vector_ptr_init
bitset_ttype#
Unit tests
An array of bits stored in 64-bit words.
typedef struct og_bitset_t { og_uint_t *data; og_int_t size; og_int_t capacity; } og_bitset_t;
Bit i is bit (i mod 64) of word i / 64, so bit 0 is the lowest bit of word 0. size and capacity count bits; words beyond size are storage only, and OG_VECTOR(bs) gives the word array. The macros OG_BIT_SET(bs, i), OG_BIT_CLEAR(bs, i), OG_BIT_TEST(bs, i), OG_BIT_MASK(i), OG_BIT_SLOT(i) and OG_BIT_NSLOTS(nbits) work on it, with OG_INTEGER_SIZE (64) bits per word; they take the bitset itself, not a pointer.
The type is defined with the vectors; the og_bitset_* functions belong to the containers area.
Creating and destroying
vector_init#
Unit tests
Creates a vector of a given length with every element zero.
og_error_t og_vector_init(og_vector_t *v, og_int_t size);
The elements are 0 (false for bool, 0 + 0i for complex, NULL for pointer vectors). Storage for at least one element is allocated even for size 0. Every initialised vector must be released with vector_destroy.
Variants with the same arguments for the other element types: og_vector_int_init, og_vector_bool_init, og_vector_char_init, og_vector_complex_init, vector_ptr_init.
- Parameters
vVector object to initialise.sizeNumber of elements, 0 or more.
- Returns
OG_SUCCESS, or the error code.- Errors
OG_EINVALsize is negative.OG_ENOMEMMemory could not be allocated.
- Complexity
- O(size).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_init- In notebooks
Og.Native.og_vector_init- igraph 1.0
igraph_vector_init- See also
vector_destroy,vector_init_array,vector_push_back
og_vector_t v;
og_vector_init(&v, 3); /* 0 0 0 */
VECTOR(v)[1] = 2.5;
og_vector_push_back(&v, 7.0); /* 0 2.5 0 7 */
og_vector_print(&v);
og_vector_destroy(&v);
vector_init_array#
Unit tests
Creates a vector holding a copy of the values of a C array.
og_error_t og_vector_init_array(
og_vector_t *v,
const og_real_t *data,
og_int_t length
);
The vector gets length elements copied from data; the array is not referenced afterwards (vector_view borrows instead).
Variants with the same arguments for the other element types: og_vector_int_init_array, og_vector_bool_init_array, og_vector_char_init_array, og_vector_complex_init_array, og_vector_ptr_init_array.
- Parameters
vVector object to initialise.dataThe values.lengthNumber of values.
- Returns
OG_SUCCESS, or the error code.- Errors
OG_EINVALlength is negative.OG_ENOMEMMemory could not be allocated.
- Complexity
- O(length).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_init_array- In notebooks
Og.Native.og_vector_init_array- igraph 1.0
igraph_vector_init_array- See also
vector_view,vector_copy_to
vector_init_copy#
Unit tests
Creates a vector with the same elements as another.
og_error_t og_vector_init_copy(og_vector_t *to, const og_vector_t *from);
to must not hold a live vector. For pointer vectors the copy is shallow: the pointers are copied, not the objects behind them, and the copy inherits the item destructor.
Variants with the same arguments for the other element types: og_vector_int_init_copy, og_vector_bool_init_copy, og_vector_char_init_copy, og_vector_complex_init_copy, vector_ptr_init_copy.
- Parameters
toVector object to initialise.fromVector to copy.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_init_copy- In notebooks
Og.Native.og_vector_init_copy- igraph 1.0
igraph_vector_init_copy- See also
vector_update,vector_ptr_init_copy
vector_init_range#
Unit tests
Creates a vector holding start, start + 1, ..., up to but not including end.
og_error_t og_vector_init_range(
og_vector_t *v,
og_real_t start,
og_real_t end
);
The range is half-open; end <= start gives an empty vector. Real form: element i is the rounded sum start + i, kept while it is below end, and the length is found by bisection, so it is right even when end - start itself rounds (vector_range(&v, 4.8, 9.8) gives the five values 4.8 .. 8.8). Int form: the length end - start is computed exactly.
Variants with the same arguments for the other element types: og_vector_int_init_range.
- Parameters
vVector object to initialise.startFirst value.endBound the values stay below.
- Returns
OG_SUCCESS, or the error code.- Errors
OG_EINVALReal form: start or end is infinite (and end > start).OG_ENOMEMThe range has more elements thanog_int_tcan count, or memory could not be allocated.
- Complexity
- O(n) for n elements, plus O(log n) to find n (real form).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c); a dedicated range and aliasing check (tests/vectors/verify4.c).
- C name
og_vector_init_range- In notebooks
Og.Native.og_vector_init_range- igraph 1.0
igraph_vector_init_range- See also
vector_range
vector_destroy#
Unit tests
Frees a vector's storage.
void og_vector_destroy(og_vector_t *v);
A pointer vector first runs its item destructor on each element that is not NULL (the elements' own memory is not freed: see vector_ptr_destroy_all). NULL and an already destroyed vector are accepted, so vectors can sit on the cleanup stack. Never call it on a view.
Variants with the same arguments for the other element types: og_vector_int_destroy, og_vector_bool_destroy, og_vector_char_destroy, og_vector_complex_destroy, vector_ptr_destroy.
- Parameters
vThe vector.
- Returns
- Nothing.
- Complexity
- O(1); O(n) destructor calls for pointer vectors.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_destroy- In notebooks
Og.Native.og_vector_destroy- igraph 1.0
igraph_vector_destroy- See also
vector_init,vector_ptr_destroy_all
vector_view#
Unit tests
Wraps an existing C array as a vector, without copying.
og_vector_t og_vector_view(const og_real_t *data, og_int_t length);
The result borrows data, with size and capacity equal to length. Use it to pass an array where a constant vector is expected. Never resize, grow or destroy a view, and keep the array alive while the view is used.
Variants with the same arguments for the other element types: og_vector_int_view, og_vector_bool_view, og_vector_char_view, og_vector_complex_view, og_vector_ptr_view.
- Parameters
dataThe array.lengthNumber of elements.
- Returns
- The view (a vector value).
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a verifier pass over the bool, char and pointer instantiations.
- C name
og_vector_view- In notebooks
Og.Native.og_vector_view- igraph 1.0
igraph_vector_view- See also
vector_init_array
Reading and setting elements
vector_null#
Unit tests
Overwrites all elements with the zero value of the element type.
void og_vector_null(og_vector_t *v);
0, false, 0 + 0i or NULL depending on the element type. The size does not change, and for pointer vectors no item destructor runs.
Variants with the same arguments for the other element types: og_vector_int_null, og_vector_bool_null, og_vector_char_null, og_vector_complex_null, og_vector_ptr_null.
- Parameters
vThe vector.
- Returns
- Nothing.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_null- In notebooks
Og.Native.og_vector_null- igraph 1.0
igraph_vector_null- See also
vector_fill
vector_fill#
Unit tests
Sets every element to the same value.
void og_vector_fill(og_vector_t *v, og_real_t e);
The size does not change.
Variants with the same arguments for the other element types: og_vector_int_fill, og_vector_bool_fill, og_vector_char_fill, og_vector_complex_fill, og_vector_ptr_fill.
- Parameters
vThe vector.eThe value.
- Returns
- Nothing.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_fill- In notebooks
Og.Native.og_vector_fill- igraph 1.0
igraph_vector_fill- See also
vector_null
vector_range#
Unit tests
Fills a vector with start, start + 1, ..., up to but not including end.
og_error_t og_vector_range(og_vector_t *v, og_real_t start, og_real_t end);
The vector is resized to the number of such values (0 when end <= start). Real form: element i is the rounded sum start + i, kept while it is below end, and the length is found by bisection, so it is right even when end - start itself rounds (vector_range(&v, 4.8, 9.8) gives the five values 4.8 .. 8.8). Int form: the length end - start is computed exactly.
Variants with the same arguments for the other element types: og_vector_int_range.
- Parameters
vThe vector.startFirst value.endBound the values stay below.
- Returns
OG_SUCCESS, or the error code.- Errors
OG_EINVALReal form: start or end is infinite (and end > start).OG_ENOMEMThe range has more elements thanog_int_tcan count, or memory could not be allocated.
- Complexity
- O(n) for n elements, plus O(log n) to find n (real form).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures; a dedicated range and aliasing check (tests/vectors/verify4.c).
- C name
og_vector_range- In notebooks
Og.Native.og_vector_range- igraph 1.0
igraph_vector_range- See also
vector_init_range
vector_get#
Unit tests
Reads one element.
og_real_t og_vector_get(const og_vector_t *v, og_int_t pos);
The same as OG_VECTOR(*v)[pos]. Positions are not checked: staying inside 0 .. size - 1 is the caller's job.
Variants with the same arguments for the other element types: og_vector_int_get, og_vector_bool_get, og_vector_char_get, og_vector_complex_get, vector_ptr_get.
- Parameters
vThe vector.posPosition.
- Returns
- The element.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_get- In notebooks
Og.Native.og_vector_get- igraph 1.0
igraph_vector_get- See also
vector_set,vector_get_ptr
vector_get_ptr#
Unit tests
The address of one element.
og_real_t *og_vector_get_ptr(const og_vector_t *v, og_int_t pos);
The pointer stays valid until the vector is resized, grows or is destroyed. Positions are not checked: staying inside 0 .. size - 1 is the caller's job.
Variants with the same arguments for the other element types: og_vector_int_get_ptr, og_vector_bool_get_ptr, og_vector_char_get_ptr, og_vector_complex_get_ptr, og_vector_ptr_get_ptr.
- Parameters
vThe vector.posPosition.
- Returns
- Pointer to the element.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_get_ptr- In notebooks
Og.Native.og_vector_get_ptr- igraph 1.0
igraph_vector_get_ptr- See also
vector_get
vector_set#
Unit tests
Writes one element.
void og_vector_set(og_vector_t *v, og_int_t pos, og_real_t value);
The same as OG_VECTOR(*v)[pos] = value. Positions are not checked: staying inside 0 .. size - 1 is the caller's job.
Variants with the same arguments for the other element types: og_vector_int_set, og_vector_bool_set, og_vector_char_set, og_vector_complex_set, vector_ptr_set.
- Parameters
vThe vector.posPosition.valueNew value.
- Returns
- Nothing.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_set- In notebooks
Og.Native.og_vector_set- igraph 1.0
igraph_vector_set- See also
vector_get
vector_tail#
Unit tests
Reads the final entry without removing it.
og_real_t og_vector_tail(const og_vector_t *v);
The vector must not be empty: calling it on an empty vector is a fatal error (OG_ASSERT).
Variants with the same arguments for the other element types: og_vector_int_tail, og_vector_bool_tail, og_vector_char_tail, og_vector_complex_tail, og_vector_ptr_tail.
- Parameters
vThe vector.
- Returns
- The last element.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_tail- In notebooks
Og.Native.og_vector_tail- igraph 1.0
igraph_vector_tail- See also
vector_pop_back
vector_index#
Unit tests
Builds a vector from chosen elements of another: newv[i] = v[idx[i]].
og_error_t og_vector_index(
const og_vector_t *v,
og_vector_t *newv,
const og_vector_int_t *idx
);
newv is resized to the length of idx. Indices may repeat and need not be sorted; they are not checked. newv may be v itself, in which case this is vector_index_in_place.
Variants with the same arguments for the other element types: og_vector_int_index, og_vector_bool_index, og_vector_char_index, og_vector_complex_index, og_vector_ptr_index.
- Parameters
vSource vector.newvInitialised vector for the result.idxPositions in v.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated; the vector is left as it was.
- Complexity
- O(k) for k indices.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_index- In notebooks
Og.Native.og_vector_index- igraph 1.0
igraph_vector_index- See also
vector_index_in_place,vector_permute
vector_index_in_place#
Unit tests
Replaces a vector by chosen elements of itself: v[i] becomes the old v[idx[i]].
og_error_t og_vector_index_in_place(
og_vector_t *v,
const og_vector_int_t *idx
);
The vector takes the length of idx. Indices may repeat and are not checked. A temporary copy is used, so on OG_ENOMEM the vector is unchanged.
Variants with the same arguments for the other element types: og_vector_int_index_in_place, og_vector_bool_index_in_place, og_vector_char_index_in_place, og_vector_complex_index_in_place, og_vector_ptr_index_in_place.
- Parameters
vThe vector.idxPositions in the old vector.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated; the vector is left as it was.
- Complexity
- O(k) for k indices.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_index_in_place- In notebooks
Og.Native.og_vector_index_in_place- igraph 1.0
igraph_vector_index_in_place- See also
vector_index,vector_permute
vector_copy_to#
Unit tests
Copies all elements into a C array.
void og_vector_copy_to(const og_vector_t *v, og_real_t *to);
to must have room for vector_size(v) elements.
Variants with the same arguments for the other element types: og_vector_int_copy_to, og_vector_bool_copy_to, og_vector_char_copy_to, og_vector_complex_copy_to, og_vector_ptr_copy_to.
- Parameters
vThe vector.toDestination array.
- Returns
- Nothing.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a verifier pass over the bool, char and pointer instantiations.
- C name
og_vector_copy_to- In notebooks
Og.Native.og_vector_copy_to- igraph 1.0
igraph_vector_copy_to- See also
vector_init_array
vector_update#
Unit tests
Makes one vector an element-by-element copy of another.
og_error_t og_vector_update(og_vector_t *to, const og_vector_t *from);
to is resized to from's size and receives its elements; its storage is reused when large enough. to and from may be the same vector.
Variants with the same arguments for the other element types: og_vector_int_update, og_vector_bool_update, og_vector_char_update, og_vector_complex_update, og_vector_ptr_update.
- Parameters
toInitialised vector to overwrite.fromVector to copy.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated; the vector is left as it was.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_update- In notebooks
Og.Native.og_vector_update- igraph 1.0
igraph_vector_update- See also
vector_init_copy,vector_append
vector_append#
Unit tests
Appends the elements of one vector to the end of another.
og_error_t og_vector_append(og_vector_t *to, const og_vector_t *from);
from may be to itself, which doubles the vector.
Variants with the same arguments for the other element types: og_vector_int_append, og_vector_bool_append, og_vector_char_append, og_vector_complex_append, og_vector_ptr_append.
- Parameters
toVector to extend.fromVector whose elements are appended.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated; the vector is left as it was.
- Complexity
- O(len(from)) amortised.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_append- In notebooks
Og.Native.og_vector_append- igraph 1.0
igraph_vector_append- See also
vector_update,vector_push_back
vector_swap#
Unit tests
Exchanges the contents of two vectors.
void og_vector_swap(og_vector_t *v1, og_vector_t *v2);
Only the internal pointers and counts are exchanged, so the cost does not depend on the sizes.
Variants with the same arguments for the other element types: og_vector_int_swap, og_vector_bool_swap, og_vector_char_swap, og_vector_complex_swap, og_vector_ptr_swap.
- Parameters
v1First vector.v2Second vector.
- Returns
- Nothing.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_swap- In notebooks
Og.Native.og_vector_swap- igraph 1.0
igraph_vector_swap- See also
vector_swap_elements
vector_swap_elements#
Unit tests
Exchanges two elements.
void og_vector_swap_elements(og_vector_t *v, og_int_t i, og_int_t j);
Positions are not checked: staying inside 0 .. size - 1 is the caller's job.
Variants with the same arguments for the other element types: og_vector_int_swap_elements, og_vector_bool_swap_elements, og_vector_char_swap_elements, og_vector_complex_swap_elements, og_vector_ptr_swap_elements.
- Parameters
vThe vector.iFirst position.jSecond position.
- Returns
- Nothing.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_swap_elements- In notebooks
Og.Native.og_vector_swap_elements- igraph 1.0
igraph_vector_swap_elements- See also
vector_swap
Sorting and rearranging
vector_reverse#
Unit tests
Reverses the order of the elements.
void og_vector_reverse(og_vector_t *v);
In place.
Variants with the same arguments for the other element types: og_vector_int_reverse, og_vector_bool_reverse, og_vector_char_reverse, og_vector_complex_reverse, og_vector_ptr_reverse.
- Parameters
vThe vector.
- Returns
- Nothing.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_reverse- In notebooks
Og.Native.og_vector_reverse- igraph 1.0
igraph_vector_reverse- See also
vector_reverse_section,vector_reverse_sort
vector_reverse_section#
Unit tests
Reverses the elements at positions from .. to - 1.
void og_vector_reverse_section(og_vector_t *v, og_int_t from, og_int_t to);
Half-open range, in place. Positions are not checked: staying inside 0 .. size - 1 is the caller's job.
Variants with the same arguments for the other element types: og_vector_int_reverse_section, og_vector_bool_reverse_section, og_vector_char_reverse_section, og_vector_complex_reverse_section, og_vector_ptr_reverse_section.
- Parameters
vThe vector.fromFirst position.toOne past the last position.
- Returns
- Nothing.
- Complexity
- O(to - from).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_reverse_section- In notebooks
Og.Native.og_vector_reverse_section- igraph 1.0
igraph_vector_reverse_section- See also
vector_reverse,vector_rotate_left
vector_rotate_left#
Unit tests
Cyclic shift: moves every element n positions towards the front, wrapping around.
void og_vector_rotate_left(og_vector_t *v, og_int_t n);
The element at position n moves to position 0 and the first n elements move to the end. n is taken modulo the size, so a negative n rotates to the right. Done in place with three reversals.
Variants with the same arguments for the other element types: og_vector_int_rotate_left, og_vector_bool_rotate_left, og_vector_char_rotate_left, og_vector_complex_rotate_left, og_vector_ptr_rotate_left.
- Parameters
vThe vector.nNumber of places.
- Returns
- Nothing.
- Complexity
- O(size).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_rotate_left- In notebooks
Og.Native.og_vector_rotate_left- igraph 1.0
igraph_vector_rotate_left- See also
vector_reverse_section
vector_shuffle#
Same quality
Puts the elements in a uniformly random order.
void og_vector_shuffle(og_vector_t *v);
Fisher-Yates (Durstenfeld) shuffle with the calling thread's default generator: for i from size - 1 down to 1, element i is exchanged with an element chosen uniformly from 0 .. i (rng_get_integer). Seed rng_default() for a reproducible order.
Variants with the same arguments for the other element types: og_vector_int_shuffle, og_vector_bool_shuffle, og_vector_char_shuffle, og_vector_complex_shuffle, og_vector_ptr_shuffle.
- Parameters
vThe vector.
- Returns
- Nothing.
- Complexity
- O(n).
- Checked
- Chi-square tests: all 24 orders of 4 elements and every value/position pair of 10 elements equally likely (p = 0.001); reproducible from the seed. Not compared draw by draw with igraph.
- C name
og_vector_shuffle- In notebooks
Og.Native.og_vector_shuffle- igraph 1.0
igraph_vector_shuffle- See also
rng_default,rng_get_integer
vector_permute#
Unit tests
Reorders a vector by an index vector: position i receives the old element index[i].
og_error_t og_vector_permute(og_vector_t *v, const og_vector_int_t *index);
The same operation as vector_index_in_place: index[i] names the position in the old vector of the element that goes to position i. An index vector shorter than v keeps only the elements it names. Indices are not checked.
Variants with the same arguments for the other element types: og_vector_int_permute, og_vector_bool_permute, og_vector_char_permute, og_vector_complex_permute, vector_ptr_permute.
- Parameters
vThe vector.indexFor each new position, the old position.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated; the vector is left as it was.
- Complexity
- O(k) for k indices.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_permute- In notebooks
Og.Native.og_vector_permute- igraph 1.0
igraph_vector_permute- See also
vector_index_in_place,vector_sort_ind
vector_sort#
Unit tests
Puts the entries in increasing order, in place (introsort).
void og_vector_sort(og_vector_t *v);
Introsort: quicksort with a median-of-three pivot, heapsort when the recursion gets too deep, insertion sort for short runs, so O(n log n) even on adversarial input. It is not stable, which only shows for reals that compare equal but differ in bits (-0 and +0). NaN values go to the end. Pointer vectors are sorted with vector_ptr_sort and a comparison function.
Variants with the same arguments for the other element types: og_vector_int_sort, og_vector_bool_sort, og_vector_char_sort.
- Parameters
vThe vector.
- Returns
- Nothing.
- Complexity
- O(n log n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_sort- In notebooks
Og.Native.og_vector_sort- igraph 1.0
igraph_vector_sort- See also
vector_reverse_sort,vector_sort_ind,vector_ptr_sort
vector_reverse_sort#
Unit tests
Puts the entries in decreasing order, in place.
void og_vector_reverse_sort(og_vector_t *v);
Sorts ascending and reverses, so NaN values come first.
Variants with the same arguments for the other element types: og_vector_int_reverse_sort, og_vector_bool_reverse_sort, og_vector_char_reverse_sort.
- Parameters
vThe vector.
- Returns
- Nothing.
- Complexity
- O(n log n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_reverse_sort- In notebooks
Og.Native.og_vector_reverse_sort- igraph 1.0
igraph_vector_reverse_sort- See also
vector_sort
vector_sort_ind#
Unit tests
The permutation that sorts a vector, leaving the vector itself unchanged.
og_error_t og_vector_sort_ind(
const og_vector_t *v,
og_vector_int_t *inds,
og_order_t order
);
inds is resized to v's size and receives positions such that v[inds[0]], v[inds[1]], ... is ascending (OG_ASCENDING) or descending (OG_DESCENDING). The sort is a stable merge sort in both directions: equal elements keep their index order. NaN counts as larger than every number.
og_vector_int_sort_ind also accepts v itself as inds; the vector is then replaced by its sorting permutation (out of memory leaves it as it was). The pointer-vector form is vector_ptr_sort_ind.
Variants with the same arguments for the other element types: og_vector_int_sort_ind, og_vector_bool_sort_ind, og_vector_char_sort_ind.
- Parameters
vThe vector.indsInitialised integer vector for the positions.orderOG_ASCENDINGorOG_DESCENDING.
- Returns
OG_SUCCESS, or the error code.- Errors
OG_EINVALorder is neitherOG_ASCENDINGnorOG_DESCENDING.OG_ENOMEMMemory could not be allocated.
- Complexity
- O(n log n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures; a dedicated range and aliasing check (tests/vectors/verify4.c).
- C name
og_vector_sort_ind- In notebooks
Og.Native.og_vector_sort_ind- igraph 1.0
igraph_vector_sort_ind- See also
vector_sort,vector_permute,vector_ptr_sort_ind
og_vector_t score;
og_vector_int_t order;
og_vector_init_real(&score, 4, 0.3, 0.9, 0.1, 0.9);
og_vector_int_init(&order, 0);
og_vector_sort_ind(&score, &order, OG_DESCENDING);
og_vector_int_print(&order); /* 1 3 0 2: ties keep their index order */
og_vector_int_destroy(&order);
og_vector_destroy(&score);
Arithmetic
vector_add_constant#
Unit tests
Adds the same value to every element.
void og_vector_add_constant(og_vector_t *v, og_real_t plus);
Int arithmetic wraps around modulo 2^64 on overflow, the same on every platform; char arithmetic is done in int and converted back; reals follow IEEE 754; complex numbers use complex arithmetic.
Variants with the same arguments for the other element types: og_vector_int_add_constant, og_vector_char_add_constant, og_vector_complex_add_constant.
- Parameters
vThe vector.plusThe value to add.
- Returns
- Nothing.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_add_constant- In notebooks
Og.Native.og_vector_add_constant- igraph 1.0
igraph_vector_add_constant- See also
vector_scale,vector_add
vector_scale#
Unit tests
Multiplies every element by the same value.
void og_vector_scale(og_vector_t *v, og_real_t by);
Int arithmetic wraps around modulo 2^64 on overflow, the same on every platform; char arithmetic is done in int and converted back; reals follow IEEE 754; complex numbers use complex arithmetic.
Variants with the same arguments for the other element types: og_vector_int_scale, og_vector_char_scale, og_vector_complex_scale.
- Parameters
vThe vector.byThe factor.
- Returns
- Nothing.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_scale- In notebooks
Og.Native.og_vector_scale- igraph 1.0
igraph_vector_scale- See also
vector_add_constant,vector_mul
vector_add#
Unit tests
Adds a second vector element by element: v1[i] += v2[i].
og_error_t og_vector_add(og_vector_t *v1, const og_vector_t *v2);
Int arithmetic wraps around modulo 2^64 on overflow, the same on every platform; char arithmetic is done in int and converted back; reals follow IEEE 754; complex numbers use complex arithmetic.
Variants with the same arguments for the other element types: og_vector_int_add, og_vector_char_add, og_vector_complex_add.
- Parameters
v1Vector that receives the result.v2Vector of the same length.
- Returns
OG_SUCCESS, orOG_EINVAL.- Errors
OG_EINVALThe two vectors differ in length; nothing is changed.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_add- In notebooks
Og.Native.og_vector_add- igraph 1.0
igraph_vector_add- See also
vector_sub,vector_add_constant
vector_sub#
Unit tests
Subtracts a second vector element by element: v1[i] -= v2[i].
og_error_t og_vector_sub(og_vector_t *v1, const og_vector_t *v2);
Int arithmetic wraps around modulo 2^64 on overflow, the same on every platform; char arithmetic is done in int and converted back; reals follow IEEE 754; complex numbers use complex arithmetic.
Variants with the same arguments for the other element types: og_vector_int_sub, og_vector_char_sub, og_vector_complex_sub.
- Parameters
v1Vector that receives the result.v2Vector of the same length.
- Returns
OG_SUCCESS, orOG_EINVAL.- Errors
OG_EINVALThe two vectors differ in length; nothing is changed.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_sub- In notebooks
Og.Native.og_vector_sub- igraph 1.0
igraph_vector_sub- See also
vector_add
vector_mul#
Unit tests
Multiplies by a second vector element by element: v1[i] *= v2[i].
og_error_t og_vector_mul(og_vector_t *v1, const og_vector_t *v2);
Int arithmetic wraps around modulo 2^64 on overflow, the same on every platform; char arithmetic is done in int and converted back; reals follow IEEE 754; complex numbers use complex arithmetic.
Variants with the same arguments for the other element types: og_vector_int_mul, og_vector_char_mul, og_vector_complex_mul.
- Parameters
v1Vector that receives the result.v2Vector of the same length.
- Returns
OG_SUCCESS, orOG_EINVAL.- Errors
OG_EINVALThe two vectors differ in length; nothing is changed.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_mul- In notebooks
Og.Native.og_vector_mul- igraph 1.0
igraph_vector_mul- See also
vector_div,vector_scale
vector_div#
Unit tests
Divides by a second vector element by element: v1[i] /= v2[i].
og_error_t og_vector_div(og_vector_t *v1, const og_vector_t *v2);
Reals divide as IEEE 754 says (x / 0 is an infinity or NaN). For int and char a zero divisor is refused with OG_EINVAL before anything is written, and OG_INTEGER_MIN / -1 wraps to OG_INTEGER_MIN; integer division truncates toward zero. Complex division uses Smith's method (1962), which avoids needless overflow.
Variants with the same arguments for the other element types: og_vector_int_div, og_vector_char_div, og_vector_complex_div.
- Parameters
v1Vector that receives the result.v2Vector of the same length.
- Returns
OG_SUCCESS, orOG_EINVAL.- Errors
OG_EINVALThe two vectors differ in length; nothing is changed.OG_EINVALInt or char: v2 contains a zero; nothing is changed.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_div- In notebooks
Og.Native.og_vector_div- igraph 1.0
igraph_vector_div- See also
vector_mul
vector_floor#
Unit tests
Rounds every element of a real vector down into an integer vector.
og_error_t og_vector_floor(const og_vector_t *from, og_vector_int_t *to);
to is resized to from's size and receives floor(from[i]). Every element is checked first, so on an error to is untouched.
- Parameters
fromReal vector.toInitialised integer vector for the result.
- Returns
OG_SUCCESS, or the error code.- Errors
OG_EINVALAn element is NaN.OG_EOVERFLOWAn element's floor lies outsideog_int_t(infinities included).OG_ENOMEMMemory could not be allocated.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_floor- In notebooks
Og.Native.og_vector_floor- igraph 1.0
igraph_vector_floor- See also
vector_range
vector_sum#
Unit tests
Adds up all entries.
og_real_t og_vector_sum(const og_vector_t *v);
0 for an empty vector. Reals are added in index order; int sums wrap around modulo 2^64 on overflow.
Variants with the same arguments for the other element types: og_vector_int_sum, og_vector_char_sum, og_vector_complex_sum.
- Parameters
vThe vector.
- Returns
- The sum.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_sum- In notebooks
Og.Native.og_vector_sum- igraph 1.0
igraph_vector_sum- See also
vector_prod
vector_prod#
Unit tests
Multiplies all entries together.
og_real_t og_vector_prod(const og_vector_t *v);
1 for an empty vector. Int products wrap around modulo 2^64 on overflow.
Variants with the same arguments for the other element types: og_vector_int_prod, og_vector_char_prod, og_vector_complex_prod.
- Parameters
vThe vector.
- Returns
- The product.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_prod- In notebooks
Og.Native.og_vector_prod- igraph 1.0
igraph_vector_prod- See also
vector_sum
Complex vectors
vector_complex_real#
Unit tests
Copies out the real component of each complex entry.
og_error_t og_vector_complex_real(
const og_vector_complex_t *v,
og_vector_t *real
);
real is resized to v's size and receives the real parts.
- Parameters
vThe complex vector.realInitialised real vector for the result.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_complex_real- In notebooks
Og.Native.og_vector_complex_real- igraph 1.0
igraph_vector_complex_real- See also
vector_complex_imag,vector_complex_realimag
vector_complex_imag#
Unit tests
Copies out the imaginary component of each complex entry.
og_error_t og_vector_complex_imag(
const og_vector_complex_t *v,
og_vector_t *imag
);
imag is resized to v's size and receives the imaginary parts.
- Parameters
vThe complex vector.imagInitialised real vector for the result.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_complex_imag- In notebooks
Og.Native.og_vector_complex_imag- igraph 1.0
igraph_vector_complex_imag- See also
vector_complex_real,vector_complex_realimag
vector_complex_realimag#
Unit tests
Copies out both components of each complex entry in a single call.
og_error_t og_vector_complex_realimag(
const og_vector_complex_t *v,
og_vector_t *real,
og_vector_t *imag
);
Both outputs are resized to v's size. Room for both is made before either is resized, so on OG_ENOMEM neither output has changed size.
- Parameters
vThe complex vector.realInitialised real vector for the real parts.imagInitialised real vector for the imaginary parts.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated; neither output changed size.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references.
- C name
og_vector_complex_realimag- In notebooks
Og.Native.og_vector_complex_realimag- igraph 1.0
igraph_vector_complex_realimag- See also
vector_complex_create
vector_complex_create#
Unit tests
Makes a new complex vector by pairing two real vectors as components.
og_error_t og_vector_complex_create(
og_vector_complex_t *v,
const og_vector_t *real,
const og_vector_t *imag
);
v must not hold a live vector; it is created with the parts' length and element i is real[i] + imag[i] i.
- Parameters
vComplex vector object to initialise.realReal parts.imagImaginary parts.
- Returns
OG_SUCCESS, or the error code.- Errors
OG_EINVALreal and imag differ in length.OG_ENOMEMMemory could not be allocated.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_complex_create- In notebooks
Og.Native.og_vector_complex_create- igraph 1.0
igraph_vector_complex_create- See also
vector_complex_create_polar,vector_complex_realimag
vector_complex_create_polar#
Unit tests
Builds a complex vector from magnitudes and angles.
og_error_t og_vector_complex_create_polar(
og_vector_complex_t *v,
const og_vector_t *r,
const og_vector_t *theta
);
v must not hold a live vector. Element i is r[i] cos(theta[i]) + i r[i] sin(theta[i]); angles are in radians.
- Parameters
vComplex vector object to initialise.rMagnitudes.thetaAngles in radians.
- Returns
OG_SUCCESS, or the error code.- Errors
OG_EINVALr and theta differ in length.OG_ENOMEMMemory could not be allocated.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_complex_create_polar- In notebooks
Og.Native.og_vector_complex_create_polar- igraph 1.0
igraph_vector_complex_create_polar- See also
vector_complex_create
vector_complex_all_almost_e#
Unit tests
Tells whether two complex vectors agree element by element within a relative tolerance.
og_bool_t og_vector_complex_all_almost_e(
const og_vector_complex_t *lhs,
const og_vector_complex_t *rhs,
og_real_t eps
);
true when the sizes agree and, at every position, a == b or |a - b| / (|a| + |b|) < eps, with |.| the complex modulus (parts are rescaled when a modulus would overflow). eps = 0 asks for exact equality. The test is complex_almost_equals from the spatial area.
- Parameters
lhsFirst vector.rhsSecond vector.epsRelative tolerance, 0 or more.
- Returns
- true or false.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_complex_all_almost_e- In notebooks
Og.Native.og_vector_complex_all_almost_e- igraph 1.0
igraph_vector_complex_all_almost_e- See also
vector_all_almost_e
vector_complex_zapsmall#
Unit tests
Zeroes tiny real and imaginary parts, each part on its own.
og_error_t og_vector_complex_zapsmall(
og_vector_complex_t *v,
og_real_t tol
);
A real or imaginary part with magnitude below tol becomes exactly 0. tol = 0 picks DBL_EPSILON^(2/3), about 3.7e-11.
- Parameters
vThe complex vector.tolThreshold, 0 or more (0: the default).
- Returns
OG_SUCCESS, orOG_EINVAL.- Errors
OG_EINVALtol is negative or NaN.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_complex_zapsmall- In notebooks
Og.Native.og_vector_complex_zapsmall- igraph 1.0
igraph_vector_complex_zapsmall- See also
vector_zapsmall
Comparing
vector_all_e#
Unit tests
Tells whether two vectors have the same size and equal elements.
og_bool_t og_vector_all_e(const og_vector_t *lhs, const og_vector_t *rhs);
Elements compare with ==, so a NaN equals nothing (two vectors holding NaN are not equal) and -0 equals +0. Complex numbers are equal when both parts are; pointer vectors compare the pointers.
Variants with the same arguments for the other element types: og_vector_int_all_e, og_vector_bool_all_e, og_vector_char_all_e, og_vector_complex_all_e, og_vector_ptr_all_e.
- Parameters
lhsFirst vector.rhsSecond vector.
- Returns
- true or false.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_all_e- In notebooks
Og.Native.og_vector_all_e- igraph 1.0
igraph_vector_all_e- See also
vector_is_equal,vector_all_almost_e,vector_lex_cmp
vector_all_almost_e#
Unit tests
Tells whether two real vectors agree element by element within a relative tolerance.
og_bool_t og_vector_all_almost_e(
const og_vector_t *lhs,
const og_vector_t *rhs,
og_real_t eps
);
true when the sizes agree and, at every position, a == b or |a - b| / (|a| + |b|) < eps. eps = 0 asks for exact equality. Equal infinities agree; a NaN never does. The test is almost_equals from the spatial area. Complex vectors use vector_complex_all_almost_e.
- Parameters
lhsFirst vector.rhsSecond vector.epsRelative tolerance, 0 or more.
- Returns
- true or false.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_all_almost_e- In notebooks
Og.Native.og_vector_all_almost_e- igraph 1.0
igraph_vector_all_almost_e- See also
vector_complex_all_almost_e,vector_all_e,vector_zapsmall
vector_all_l#
Unit tests
Tells whether lhs[i] < rhs[i] at every position.
og_bool_t og_vector_all_l(const og_vector_t *lhs, const og_vector_t *rhs);
false when the sizes differ or a NaN takes part; two empty vectors give true.
Variants with the same arguments for the other element types: og_vector_int_all_l, og_vector_bool_all_l, og_vector_char_all_l.
- Parameters
lhsFirst vector.rhsSecond vector.
- Returns
- true or false.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_all_l- In notebooks
Og.Native.og_vector_all_l- igraph 1.0
igraph_vector_all_l- See also
vector_all_le,vector_all_g
vector_all_g#
Unit tests
Tells whether lhs[i] > rhs[i] at every position.
og_bool_t og_vector_all_g(const og_vector_t *lhs, const og_vector_t *rhs);
false when the sizes differ or a NaN takes part; two empty vectors give true.
Variants with the same arguments for the other element types: og_vector_int_all_g, og_vector_bool_all_g, og_vector_char_all_g.
- Parameters
lhsFirst vector.rhsSecond vector.
- Returns
- true or false.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_all_g- In notebooks
Og.Native.og_vector_all_g- igraph 1.0
igraph_vector_all_g- See also
vector_all_ge,vector_all_l
vector_all_le#
Unit tests
Tells whether lhs[i] <= rhs[i] at every position.
og_bool_t og_vector_all_le(const og_vector_t *lhs, const og_vector_t *rhs);
false when the sizes differ or a NaN takes part; two empty vectors give true.
Variants with the same arguments for the other element types: og_vector_int_all_le, og_vector_bool_all_le, og_vector_char_all_le.
- Parameters
lhsFirst vector.rhsSecond vector.
- Returns
- true or false.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_all_le- In notebooks
Og.Native.og_vector_all_le- igraph 1.0
igraph_vector_all_le- See also
vector_all_l,vector_all_ge
vector_all_ge#
Unit tests
Tells whether lhs[i] >= rhs[i] at every position.
og_bool_t og_vector_all_ge(const og_vector_t *lhs, const og_vector_t *rhs);
false when the sizes differ or a NaN takes part; two empty vectors give true.
Variants with the same arguments for the other element types: og_vector_int_all_ge, og_vector_bool_all_ge, og_vector_char_all_ge.
- Parameters
lhsFirst vector.rhsSecond vector.
- Returns
- true or false.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_all_ge- In notebooks
Og.Native.og_vector_all_ge- igraph 1.0
igraph_vector_all_ge- See also
vector_all_g,vector_all_le
vector_is_equal#
Unit tests
Tells whether two vectors are equal; the same test as vector_all_e.
og_bool_t og_vector_is_equal(
const og_vector_t *lhs,
const og_vector_t *rhs
);
Same size and equal elements under ==.
Variants with the same arguments for the other element types: og_vector_int_is_equal, og_vector_bool_is_equal, og_vector_char_is_equal, og_vector_complex_is_equal, og_vector_ptr_is_equal.
- Parameters
lhsFirst vector.rhsSecond vector.
- Returns
- true or false.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_is_equal- In notebooks
Og.Native.og_vector_is_equal- igraph 1.0
igraph_vector_is_equal- See also
vector_all_e
vector_zapsmall#
Unit tests
Snaps near-zero entries to exactly 0 using an absolute threshold.
og_error_t og_vector_zapsmall(og_vector_t *v, og_real_t tol);
Every element with |x| < tol becomes 0. tol = 0 picks DBL_EPSILON^(2/3), about 3.7e-11. Useful to remove rounding noise before comparing or printing results. Complex vectors use vector_complex_zapsmall.
- Parameters
vThe vector.tolThreshold, 0 or more (0: the default).
- Returns
OG_SUCCESS, orOG_EINVAL.- Errors
OG_EINVALtol is negative or NaN.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_zapsmall- In notebooks
Og.Native.og_vector_zapsmall- igraph 1.0
igraph_vector_zapsmall- See also
vector_complex_zapsmall,vector_all_almost_e
vector_lex_cmp#
Unit tests
Compares two vectors lexicographically.
int og_vector_lex_cmp(const og_vector_t *lhs, const og_vector_t *rhs);
Returns -1, 0 or 1. For reals NaN orders after every number. The first position where the vectors differ decides; when one vector is a prefix of the other, the shorter one is smaller.
Variants with the same arguments for the other element types: og_vector_int_lex_cmp, og_vector_bool_lex_cmp, og_vector_char_lex_cmp.
- Parameters
lhsFirst vector.rhsSecond vector.
- Returns
- -1, 0 or 1.
- Complexity
- O(min(n1, n2)).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_lex_cmp- In notebooks
Og.Native.og_vector_lex_cmp- igraph 1.0
igraph_vector_lex_cmp- See also
vector_lex_cmp_untyped,vector_colex_cmp
vector_lex_cmp_untyped#
Unit tests
vector_lex_cmp in the form a qsort-style sort expects.
int og_vector_lex_cmp_untyped(const void *lhs, const void *rhs);
lhs and rhs each point to a vector pointer (an vector_t ** passed as const void *): the form qsort passes for an array of vector_t *, and vector_ptr_sort for a pointer vector holding vectors.
Variants with the same arguments for the other element types: og_vector_int_lex_cmp_untyped, og_vector_bool_lex_cmp_untyped, og_vector_char_lex_cmp_untyped.
- Parameters
lhsPointer to the first vector's pointer.rhsPointer to the second vector's pointer.
- Returns
- -1, 0 or 1.
- Complexity
- O(min(n1, n2)).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_lex_cmp_untyped- In notebooks
Og.Native.og_vector_lex_cmp_untyped- igraph 1.0
igraph_vector_lex_cmp_untyped- See also
vector_lex_cmp,vector_ptr_sort
vector_colex_cmp#
Unit tests
Compares two vectors colexicographically: from the last element backwards.
int og_vector_colex_cmp(const og_vector_t *lhs, const og_vector_t *rhs);
Returns -1, 0 or 1. For reals NaN orders after every number. The last elements are compared first, then the ones before them, and so on; when the shorter vector runs out first, it is the smaller.
Variants with the same arguments for the other element types: og_vector_int_colex_cmp, og_vector_bool_colex_cmp, og_vector_char_colex_cmp.
- Parameters
lhsFirst vector.rhsSecond vector.
- Returns
- -1, 0 or 1.
- Complexity
- O(min(n1, n2)).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_colex_cmp- In notebooks
Og.Native.og_vector_colex_cmp- igraph 1.0
igraph_vector_colex_cmp- See also
vector_colex_cmp_untyped,vector_lex_cmp
vector_colex_cmp_untyped#
Unit tests
vector_colex_cmp in the form a qsort-style sort expects.
int og_vector_colex_cmp_untyped(const void *lhs, const void *rhs);
lhs and rhs each point to a vector pointer (an vector_t ** passed as const void *): the form qsort passes for an array of vector_t *, and vector_ptr_sort for a pointer vector holding vectors.
Variants with the same arguments for the other element types: og_vector_int_colex_cmp_untyped, og_vector_bool_colex_cmp_untyped, og_vector_char_colex_cmp_untyped.
- Parameters
lhsPointer to the first vector's pointer.rhsPointer to the second vector's pointer.
- Returns
- -1, 0 or 1.
- Complexity
- O(min(n1, n2)).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_colex_cmp_untyped- In notebooks
Og.Native.og_vector_colex_cmp_untyped- igraph 1.0
igraph_vector_colex_cmp_untyped- See also
vector_colex_cmp,vector_ptr_sort
vector_maxdifference#
Unit tests
The largest absolute difference between corresponding elements of two vectors.
og_real_t og_vector_maxdifference(
const og_vector_t *m1,
const og_vector_t *m2
);
Taken over the common prefix (the shorter length) and returned as a real. 0 when either vector is empty; NaN when a difference is NaN. For int vectors each distance is computed exactly and rounded to a real once, so large values do not lose their low bits.
Variants with the same arguments for the other element types: og_vector_int_maxdifference, og_vector_bool_maxdifference, og_vector_char_maxdifference.
- Parameters
m1First vector.m2Second vector.
- Returns
- The largest |m1[i] - m2[i]|.
- Complexity
- O(min(n1, n2)).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_maxdifference- In notebooks
Og.Native.og_vector_maxdifference- igraph 1.0
igraph_vector_maxdifference- See also
vector_all_almost_e
Minimum and maximum
vector_min#
Unit tests
The smallest element.
og_real_t og_vector_min(const og_vector_t *v);
The vector must not be empty (fatal error otherwise). A real vector containing NaN gives NaN.
Variants with the same arguments for the other element types: og_vector_int_min, og_vector_bool_min, og_vector_char_min.
- Parameters
vThe vector.
- Returns
- The minimum.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_min- In notebooks
Og.Native.og_vector_min- igraph 1.0
igraph_vector_min- See also
vector_which_min,vector_minmax
vector_max#
Unit tests
The largest element.
og_real_t og_vector_max(const og_vector_t *v);
The vector must not be empty (fatal error otherwise). A real vector containing NaN gives NaN.
Variants with the same arguments for the other element types: og_vector_int_max, og_vector_bool_max, og_vector_char_max.
- Parameters
vThe vector.
- Returns
- The maximum.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_max- In notebooks
Og.Native.og_vector_max- igraph 1.0
igraph_vector_max- See also
vector_which_max,vector_minmax
vector_which_min#
Unit tests
Index where the minimum sits (the first one on ties).
og_int_t og_vector_which_min(const og_vector_t *v);
The vector must not be empty (fatal error otherwise). Among equal minima the first position is returned. If a real vector contains NaN, the position of the first NaN is returned.
Variants with the same arguments for the other element types: og_vector_int_which_min, og_vector_bool_which_min, og_vector_char_which_min.
- Parameters
vThe vector.
- Returns
- The position.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_which_min- In notebooks
Og.Native.og_vector_which_min- igraph 1.0
igraph_vector_which_min- See also
vector_min,vector_which_minmax
vector_which_max#
Unit tests
Index where the maximum sits (the first one on ties).
og_int_t og_vector_which_max(const og_vector_t *v);
The vector must not be empty (fatal error otherwise). Among equal maxima the first position is returned. If a real vector contains NaN, the position of the first NaN is returned.
Variants with the same arguments for the other element types: og_vector_int_which_max, og_vector_bool_which_max, og_vector_char_which_max.
- Parameters
vThe vector.
- Returns
- The position.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_which_max- In notebooks
Og.Native.og_vector_which_max- igraph 1.0
igraph_vector_which_max- See also
vector_max,vector_which_minmax
vector_minmax#
Unit tests
The smallest and the largest element in one pass.
void og_vector_minmax(const og_vector_t *v, og_real_t *min, og_real_t *max);
The vector must not be empty (fatal error otherwise). Either output may be NULL. If a real vector contains NaN, both outputs are NaN.
Variants with the same arguments for the other element types: og_vector_int_minmax, og_vector_bool_minmax, og_vector_char_minmax.
- Parameters
vThe vector.minReceives the minimum, or NULL.maxReceives the maximum, or NULL.
- Returns
- Nothing.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_minmax- In notebooks
Og.Native.og_vector_minmax- igraph 1.0
igraph_vector_minmax- See also
vector_which_minmax
vector_which_minmax#
Unit tests
The positions of the smallest and the largest element in one pass.
void og_vector_which_minmax(
const og_vector_t *v,
og_int_t *which_min,
og_int_t *which_max
);
The vector must not be empty (fatal error otherwise). First positions among ties. Either output may be NULL. If a real vector contains NaN, both outputs are the position of the first NaN.
Variants with the same arguments for the other element types: og_vector_int_which_minmax, og_vector_bool_which_minmax, og_vector_char_which_minmax.
- Parameters
vThe vector.which_minReceives the position of the minimum, or NULL.which_maxReceives the position of the maximum, or NULL.
- Returns
- Nothing.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_which_minmax- In notebooks
Og.Native.og_vector_which_minmax- igraph 1.0
igraph_vector_which_minmax- See also
vector_minmax
Properties and searching
vector_empty#
Unit tests
Tells whether a vector has no elements.
og_bool_t og_vector_empty(const og_vector_t *v);
The same as vector_size(v) == 0.
Variants with the same arguments for the other element types: og_vector_int_empty, og_vector_bool_empty, og_vector_char_empty, og_vector_complex_empty, og_vector_ptr_empty.
- Parameters
vThe vector.
- Returns
- true or false.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_empty- In notebooks
Og.Native.og_vector_empty- igraph 1.0
igraph_vector_empty- See also
vector_size
vector_size#
Unit tests
The number of elements.
og_int_t og_vector_size(const og_vector_t *v);
Variants with the same arguments for the other element types: og_vector_int_size, og_vector_bool_size, og_vector_char_size, og_vector_complex_size, vector_ptr_size.
- Parameters
vThe vector.
- Returns
- The size.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_size- In notebooks
Og.Native.og_vector_size- igraph 1.0
igraph_vector_size- See also
vector_capacity,vector_resize
vector_capacity#
Unit tests
The number of elements the allocated storage can hold.
og_int_t og_vector_capacity(const og_vector_t *v);
Never below the size. It at least doubles when push_back or resize need more room, and vector_resize_min trims it to the size.
Variants with the same arguments for the other element types: og_vector_int_capacity, og_vector_bool_capacity, og_vector_char_capacity, og_vector_complex_capacity, vector_ptr_capacity.
- Parameters
vThe vector.
- Returns
- The capacity.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_capacity- In notebooks
Og.Native.og_vector_capacity- igraph 1.0
igraph_vector_capacity- See also
vector_reserve,vector_resize_min
vector_isininterval#
Unit tests
Tells whether every element lies between low and high, both included.
og_bool_t og_vector_isininterval(
const og_vector_t *v,
og_real_t low,
og_real_t high
);
An empty vector gives true; a NaN element gives false.
Variants with the same arguments for the other element types: og_vector_int_isininterval, og_vector_bool_isininterval, og_vector_char_isininterval.
- Parameters
vThe vector.lowLower bound.highUpper bound.
- Returns
- true or false.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_isininterval- In notebooks
Og.Native.og_vector_isininterval- igraph 1.0
igraph_vector_isininterval- See also
vector_minmax
vector_is_nan#
Unit tests
Marks which elements are NaN.
og_error_t og_vector_is_nan(const og_vector_t *v, og_vector_bool_t *is_nan);
is_nan is resized to v's size; entry i is true when v[i] is NaN (complex: when either part is NaN).
Variants with the same arguments for the other element types: og_vector_complex_is_nan.
- Parameters
vThe vector.is_nanInitialised bool vector for the result.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_is_nan- In notebooks
Og.Native.og_vector_is_nan- igraph 1.0
igraph_vector_is_nan- See also
vector_is_any_nan,vector_is_all_finite
vector_is_any_nan#
Unit tests
True if at least one entry is not a number.
og_bool_t og_vector_is_any_nan(const og_vector_t *v);
Complex: an element is NaN when either part is.
Variants with the same arguments for the other element types: og_vector_complex_is_any_nan.
- Parameters
vThe vector.
- Returns
- true or false.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_is_any_nan- In notebooks
Og.Native.og_vector_is_any_nan- igraph 1.0
igraph_vector_is_any_nan- See also
vector_is_nan
vector_is_all_finite#
Unit tests
Tells whether every element is finite (neither infinite nor NaN).
og_bool_t og_vector_is_all_finite(const og_vector_t *v);
Complex: both parts must be finite. An empty vector gives true.
Variants with the same arguments for the other element types: og_vector_complex_is_all_finite.
- Parameters
vThe vector.
- Returns
- true or false.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_is_all_finite- In notebooks
Og.Native.og_vector_is_all_finite- igraph 1.0
igraph_vector_is_all_finite- See also
vector_is_any_nan
vector_contains#
Unit tests
Tells whether a value occurs in a vector.
og_bool_t og_vector_contains(const og_vector_t *v, og_real_t what);
A linear scan comparing with ==, so a NaN is never found. For a sorted vector vector_contains_sorted is faster.
Variants with the same arguments for the other element types: og_vector_int_contains, og_vector_bool_contains, og_vector_char_contains, og_vector_complex_contains, og_vector_ptr_contains.
- Parameters
vThe vector.whatThe value.
- Returns
- true or false.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_contains- In notebooks
Og.Native.og_vector_contains- igraph 1.0
igraph_vector_contains- See also
vector_search,vector_contains_sorted
vector_search#
Unit tests
Finds the first position at or after from that holds a value.
og_bool_t og_vector_search(
const og_vector_t *v,
og_int_t from,
og_real_t what,
og_int_t *pos
);
Compares with ==. On success *pos receives the position (pos may be NULL). A negative from starts at 0.
Variants with the same arguments for the other element types: og_vector_int_search, og_vector_bool_search, og_vector_char_search, og_vector_complex_search, og_vector_ptr_search.
- Parameters
vThe vector.fromPosition to start at.whatThe value.posReceives the position, or NULL.
- Returns
- true when found.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_search- In notebooks
Og.Native.og_vector_search- igraph 1.0
igraph_vector_search- See also
vector_contains,vector_binsearch
vector_binsearch#
Unit tests
Binary search in a sorted vector.
og_bool_t og_vector_binsearch(
const og_vector_t *v,
og_real_t what,
og_int_t *pos
);
v must be sorted in ascending order, as vector_sort leaves it. *pos (when pos is not NULL) receives the first position whose element is not less than what: the match when there is one, otherwise the position where what would be inserted to keep the order.
Variants with the same arguments for the other element types: og_vector_int_binsearch, og_vector_bool_binsearch, og_vector_char_binsearch.
- Parameters
vThe vector.whatThe value.posReceives the position, or NULL.
- Returns
- true when what occurs in v.
- Complexity
- O(log n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_binsearch- In notebooks
Og.Native.og_vector_binsearch- igraph 1.0
igraph_vector_binsearch- See also
vector_binsearch_slice,vector_contains_sorted
vector_binsearch_slice#
Unit tests
Binary search within positions start .. end - 1 of a sorted vector.
og_bool_t og_vector_binsearch_slice(
const og_vector_t *v,
og_real_t what,
og_int_t *pos,
og_int_t start,
og_int_t end
);
The slice must be sorted in ascending order. *pos (when not NULL) receives the first position in the slice whose element is not less than what, which lies between start and end. The bounds are not checked.
Variants with the same arguments for the other element types: og_vector_int_binsearch_slice, og_vector_bool_binsearch_slice, og_vector_char_binsearch_slice.
- Parameters
vThe vector.whatThe value.posReceives the position, or NULL.startFirst position of the slice.endOne past its last position.
- Returns
- true when what occurs in the slice.
- Complexity
- O(log(end - start)).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_binsearch_slice- In notebooks
Og.Native.og_vector_binsearch_slice- igraph 1.0
igraph_vector_binsearch_slice- See also
vector_binsearch
vector_contains_sorted#
Unit tests
Tells whether a value occurs in a sorted vector, by binary search.
og_bool_t og_vector_contains_sorted(const og_vector_t *v, og_real_t what);
v must be sorted in ascending order, as vector_sort leaves it.
Variants with the same arguments for the other element types: og_vector_int_contains_sorted, og_vector_bool_contains_sorted, og_vector_char_contains_sorted.
- Parameters
vThe vector.whatThe value.
- Returns
- true or false.
- Complexity
- O(log n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a Python model of the documented rules (tests/vectors/model.c).
- C name
og_vector_contains_sorted- In notebooks
Og.Native.og_vector_contains_sorted- igraph 1.0
igraph_vector_contains_sorted- See also
vector_binsearch,vector_contains
Changing the size
vector_clear#
Unit tests
Removes all elements and keeps the storage.
void og_vector_clear(og_vector_t *v);
The size becomes 0 and the capacity stays. A pointer vector first runs its item destructor on each element that is not NULL.
Variants with the same arguments for the other element types: og_vector_int_clear, og_vector_bool_clear, og_vector_char_clear, og_vector_complex_clear, vector_ptr_clear.
- Parameters
vThe vector.
- Returns
- Nothing.
- Complexity
- O(1); O(n) destructor calls for pointer vectors.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_clear- In notebooks
Og.Native.og_vector_clear- igraph 1.0
igraph_vector_clear- See also
vector_resize,vector_resize_min
vector_reserve#
Unit tests
Makes room for at least capacity elements without changing the size.
og_error_t og_vector_reserve(og_vector_t *v, og_int_t capacity);
Never shrinks the storage. Call it before many push_back calls whose number you know, to avoid repeated reallocation.
Variants with the same arguments for the other element types: og_vector_int_reserve, og_vector_bool_reserve, og_vector_char_reserve, og_vector_complex_reserve, vector_ptr_reserve.
- Parameters
vThe vector.capacityNumber of elements to make room for.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated; the vector is left as it was.
- Complexity
- O(n) when the storage moves, otherwise O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_reserve- In notebooks
Og.Native.og_vector_reserve- igraph 1.0
igraph_vector_reserve- See also
vector_capacity,vector_resize
vector_resize#
Unit tests
Changes the number of elements.
og_error_t og_vector_resize(og_vector_t *v, og_int_t new_size);
Shrinking keeps the first new_size elements and the storage. Growing keeps the existing elements; the new ones have unspecified values (NULL in pointer vectors), so set them. When the storage must grow it at least doubles, so growing one element at a time costs amortised O(1) per element.
Variants with the same arguments for the other element types: og_vector_int_resize, og_vector_bool_resize, og_vector_char_resize, og_vector_complex_resize, vector_ptr_resize.
- Parameters
vThe vector.new_sizeNew number of elements, 0 or more.
- Returns
OG_SUCCESS, or the error code.- Errors
OG_EINVALnew_size is negative.OG_ENOMEMMemory could not be allocated; the vector is left as it was.
- Complexity
- O(1) amortised per added element; O(n) when the storage moves.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_resize- In notebooks
Og.Native.og_vector_resize- igraph 1.0
igraph_vector_resize- See also
vector_reserve,vector_clear
vector_resize_min#
Unit tests
Releases unused storage: the capacity becomes equal to the size.
void og_vector_resize_min(og_vector_t *v);
Also for an empty vector, whose capacity becomes 0. If the smaller block cannot be obtained, the vector keeps its larger one; the function cannot fail.
Variants with the same arguments for the other element types: og_vector_int_resize_min, og_vector_bool_resize_min, og_vector_char_resize_min, og_vector_complex_resize_min, vector_ptr_resize_min.
- Parameters
vThe vector.
- Returns
- Nothing.
- Complexity
- O(n) when the storage moves.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_resize_min- In notebooks
Og.Native.og_vector_resize_min- igraph 1.0
igraph_vector_resize_min- See also
vector_capacity,vector_reserve
vector_push_back#
Unit tests
Grows the vector by one, storing a value at the new end.
og_error_t og_vector_push_back(og_vector_t *v, og_real_t e);
When the storage is full it at least doubles, so appending is amortised O(1). On OG_ENOMEM the vector is unchanged.
Variants with the same arguments for the other element types: og_vector_int_push_back, og_vector_bool_push_back, og_vector_char_push_back, og_vector_complex_push_back, vector_ptr_push_back.
- Parameters
vThe vector.eThe new element.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated; the vector is left as it was.
- Complexity
- O(1) amortised.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_push_back- In notebooks
Og.Native.og_vector_push_back- igraph 1.0
igraph_vector_push_back- See also
vector_pop_back,vector_insert,vector_reserve
vector_pop_back#
Unit tests
Takes the final entry off the vector and hands it back.
og_real_t og_vector_pop_back(og_vector_t *v);
The vector must not be empty (fatal error otherwise). The storage is kept. In a pointer vector no item destructor runs: the pointer is handed to the caller.
Variants with the same arguments for the other element types: og_vector_int_pop_back, og_vector_bool_pop_back, og_vector_char_pop_back, og_vector_complex_pop_back, vector_ptr_pop_back.
- Parameters
vThe vector.
- Returns
- The removed element.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_pop_back- In notebooks
Og.Native.og_vector_pop_back- igraph 1.0
igraph_vector_pop_back- See also
vector_push_back,vector_tail
vector_insert#
Unit tests
Inserts a value at a position, moving the later elements one place to the right.
og_error_t og_vector_insert(og_vector_t *v, og_int_t pos, og_real_t value);
pos may be 0 .. size; pos == size appends.
Variants with the same arguments for the other element types: og_vector_int_insert, og_vector_bool_insert, og_vector_char_insert, og_vector_complex_insert, vector_ptr_insert.
- Parameters
vThe vector.posPosition of the new element.valueThe value.
- Returns
OG_SUCCESS, or the error code.- Errors
OG_EINVALpos is outside 0 .. size.OG_ENOMEMMemory could not be allocated; the vector is left as it was.
- Complexity
- O(n - pos) amortised.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_insert- In notebooks
Og.Native.og_vector_insert- igraph 1.0
igraph_vector_insert- See also
vector_push_back,vector_remove
vector_remove#
Unit tests
Removes the element at a position, moving the later elements one place to the left.
void og_vector_remove(og_vector_t *v, og_int_t elem);
A position outside 0 .. size - 1 changes nothing. The storage is kept; in a pointer vector no item destructor runs.
Variants with the same arguments for the other element types: og_vector_int_remove, og_vector_bool_remove, og_vector_char_remove, og_vector_complex_remove, og_vector_ptr_remove.
- Parameters
vThe vector.elemPosition of the element to remove.
- Returns
- Nothing.
- Complexity
- O(n - elem).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_remove- In notebooks
Og.Native.og_vector_remove- igraph 1.0
igraph_vector_remove- See also
vector_remove_section,vector_insert
vector_remove_section#
Unit tests
Removes the elements at positions from .. to - 1.
void og_vector_remove_section(og_vector_t *v, og_int_t from, og_int_t to);
The range is clipped to the vector, and an empty range changes nothing. The storage is kept; in a pointer vector no item destructor runs.
Variants with the same arguments for the other element types: og_vector_int_remove_section, og_vector_bool_remove_section, og_vector_char_remove_section, og_vector_complex_remove_section, og_vector_ptr_remove_section.
- Parameters
vThe vector.fromFirst position to remove.toOne past the last.
- Returns
- Nothing.
- Complexity
- O(n - from).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; a Python model of the documented rules (tests/vectors/model.c); random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_remove_section- In notebooks
Og.Native.og_vector_remove_section- igraph 1.0
igraph_vector_remove_section- See also
vector_remove
Sorted vectors as sets
vector_intersect_sorted#
Unit tests
Common elements of two ascending vectors, counted with multiplicity.
og_error_t og_vector_intersect_sorted(
const og_vector_t *v1,
const og_vector_t *v2,
og_vector_t *result
);
Both inputs must be sorted in ascending order. They are treated as multisets: a value occurring k1 times in v1 and k2 times in v2 occurs min(k1, k2) times in result, which comes out sorted. An output may be one of the inputs (the inputs are copied first in that case).
Inputs of similar size are merged. When one is at least 16 times longer than the other, the walk skips ahead in it by exponential (galloping) search, so a short list against a long one costs O(m log(n/m)).
Variants with the same arguments for the other element types: og_vector_int_intersect_sorted, og_vector_bool_intersect_sorted, og_vector_char_intersect_sorted.
- Parameters
v1First sorted vector.v2Second sorted vector.resultInitialised vector for the intersection.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated.
- Complexity
- O(m + n) for similar sizes; O(m log(n/m)) when n >= 16 m (m the shorter length).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a 400-case fixture from Python's multiset arithmetic plus random cases against a pairing reference; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_intersect_sorted- In notebooks
Og.Native.og_vector_intersect_sorted- igraph 1.0
igraph_vector_intersect_sorted- See also
vector_intersection_size_sorted,vector_difference_and_intersection_sorted
vector_intersection_size_sorted#
Unit tests
The size of the multiset intersection of two sorted vectors, without building it.
og_int_t og_vector_intersection_size_sorted(
const og_vector_t *v1,
const og_vector_t *v2
);
Both inputs must be sorted in ascending order. They are treated as multisets: a value occurring k1 times in v1 and k2 times in v2 contributes min(k1, k2). Same algorithm and cost as vector_intersect_sorted.
Variants with the same arguments for the other element types: og_vector_int_intersection_size_sorted, og_vector_bool_intersection_size_sorted, og_vector_char_intersection_size_sorted.
- Parameters
v1First sorted vector.v2Second sorted vector.
- Returns
- The number of common elements, counted with multiplicity.
- Complexity
- O(m + n) for similar sizes; O(m log(n/m)) when n >= 16 m.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a 400-case fixture from Python's multiset arithmetic plus random cases against a pairing reference; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_intersection_size_sorted- In notebooks
Og.Native.og_vector_intersection_size_sorted- igraph 1.0
igraph_vector_intersection_size_sorted- See also
vector_intersect_sorted
vector_difference_sorted#
Unit tests
What remains of ascending v1 after taking away the elements of ascending v2, multiplicities subtracted.
og_error_t og_vector_difference_sorted(
const og_vector_t *v1,
const og_vector_t *v2,
og_vector_t *result
);
Both inputs must be sorted in ascending order. They are treated as multisets: a value occurring k1 times in v1 and k2 times in v2 occurs max(0, k1 - k2) times in result, which comes out sorted. Of a run of equal values the copies kept are the last ones of v1's run, the same ones vector_difference_and_intersection_sorted keeps. An output may be one of the inputs (the inputs are copied first in that case).
Inputs within a factor 16 of each other are merged one element at a time (long runs of duplicates are crossed by galloping); otherwise stretches of v1 below the next element of v2 are copied as blocks and stretches of v2 are skipped by exponential search.
Variants with the same arguments for the other element types: og_vector_int_difference_sorted, og_vector_bool_difference_sorted, og_vector_char_difference_sorted.
- Parameters
v1Sorted vector to subtract from.v2Sorted vector to subtract.resultInitialised vector for the difference.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated.
- Complexity
- O(m + n) for similar sizes; O(output + m log(n/m)) for very different sizes.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a 400-case fixture from Python's multiset arithmetic plus random cases against a pairing reference; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_difference_sorted- In notebooks
Og.Native.og_vector_difference_sorted- igraph 1.0
igraph_vector_difference_sorted- See also
vector_difference_and_intersection_sorted,vector_intersect_sorted
vector_difference_and_intersection_sorted#
Unit tests
The v1-only, v2-only and shared elements of two ascending vectors, from one merge pass.
og_error_t og_vector_difference_and_intersection_sorted(
const og_vector_t *v1,
const og_vector_t *v2,
og_vector_t *vdiff12,
og_vector_t *vdiff21,
og_vector_t *vint
);
Both inputs must be sorted in ascending order. They are treated as multisets: a value occurring k1 times in v1 and k2 times in v2 occurs max(0, k1 - k2) times in vdiff12, max(0, k2 - k1) times in vdiff21 and min(k1, k2) times in vint; all three come out sorted. Any output may be NULL when it is not wanted. An output may be one of the inputs (the inputs are copied first in that case).
Variants with the same arguments for the other element types: og_vector_int_difference_and_intersection_sorted, og_vector_bool_difference_and_intersection_sorted, og_vector_char_difference_and_intersection_sorted.
- Parameters
v1First sorted vector.v2Second sorted vector.vdiff12Initialised vector for v1 minus v2, or NULL.vdiff21Initialised vector for v2 minus v1, or NULL.vintInitialised vector for the intersection, or NULL.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated.
- Complexity
- O(m + n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a 400-case fixture from Python's multiset arithmetic plus random cases against a pairing reference; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_difference_and_intersection_sorted- In notebooks
Og.Native.og_vector_difference_and_intersection_sorted- igraph 1.0
igraph_vector_difference_and_intersection_sorted- See also
vector_difference_sorted,vector_intersect_sorted
Vectors of pointers
vector_ptr_init#
Unit tests
Creates a pointer vector of size NULL pointers.
og_error_t og_vector_ptr_init(og_vector_ptr_t *v, og_int_t size);
A pointer vector holds void * elements and may carry an item destructor, which vector_ptr_destroy, vector_ptr_clear and vector_ptr_free_all run on every element that is not NULL. A new vector has no item destructor. Release it with vector_ptr_destroy (or vector_ptr_destroy_all when it owns heap blocks).
- Parameters
vPointer vector object to initialise.sizeNumber of elements, 0 or more.
- Returns
OG_SUCCESS, or the error code.- Errors
OG_EINVALsize is negative.OG_ENOMEMMemory could not be allocated.
- Complexity
- O(size).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_init- In notebooks
Og.Native.og_vector_ptr_init- igraph 1.0
igraph_vector_ptr_init- See also
vector_ptr_set_item_destructor,vector_ptr_destroy,vector_init
vector_ptr_init_copy#
Unit tests
Creates a shallow copy of a pointer vector.
og_error_t og_vector_ptr_init_copy(
og_vector_ptr_t *to,
const og_vector_ptr_t *from
);
The pointers are copied, not the objects they point to, and the copy inherits the item destructor. If both vectors keep that destructor, destroying both destroys every object twice: remove it from one of them with vector_ptr_set_item_destructor(v, NULL).
- Parameters
toPointer vector object to initialise.fromPointer vector to copy.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_init_copy- In notebooks
Og.Native.og_vector_ptr_init_copy- igraph 1.0
igraph_vector_ptr_init_copy- See also
vector_ptr_set_item_destructor
vector_ptr_destroy#
Unit tests
Frees a pointer vector, running the item destructor on its elements.
void og_vector_ptr_destroy(og_vector_ptr_t *v);
The item destructor, if set, runs on each element that is not NULL; the elements' own memory is not freed (vector_ptr_destroy_all does that). Safe to call twice.
- Parameters
vThe pointer vector.
- Returns
- Nothing.
- Complexity
- O(n) destructor calls.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_destroy- In notebooks
Og.Native.og_vector_ptr_destroy- igraph 1.0
igraph_vector_ptr_destroy- See also
vector_ptr_destroy_all,vector_ptr_free_all
vector_ptr_free_all#
Unit tests
Destroys and frees every element, leaving NULL in each slot.
void og_vector_ptr_free_all(og_vector_ptr_t *v);
For each element that is not NULL: the item destructor (if set), then free, then NULL in the slot. The size does not change. The elements must have been allocated with malloc, calloc or realloc.
- Parameters
vThe pointer vector.
- Returns
- Nothing.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references.
- C name
og_vector_ptr_free_all- In notebooks
Og.Native.og_vector_ptr_free_all- igraph 1.0
igraph_vector_ptr_free_all- See also
vector_ptr_destroy_all
vector_ptr_destroy_all#
Unit tests
Frees every element and then the vector itself.
void og_vector_ptr_destroy_all(og_vector_ptr_t *v);
vector_ptr_free_all followed by vector_ptr_destroy: the usual way to release a pointer vector that owns heap objects. Usable as a cleanup-stack destructor.
- Parameters
vThe pointer vector.
- Returns
- Nothing.
- Complexity
- O(n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references.
- C name
og_vector_ptr_destroy_all- In notebooks
Og.Native.og_vector_ptr_destroy_all- igraph 1.0
igraph_vector_ptr_destroy_all- See also
vector_ptr_free_all,vector_ptr_destroy
og_vector_ptr_t list;
og_vector_t *item;
og_vector_ptr_init(&list, 0);
OG_VECTOR_PTR_SET_ITEM_DESTRUCTOR(&list, og_vector_destroy);
item = OG_MALLOC(1, og_vector_t);
og_vector_init(item, 10);
og_vector_ptr_push_back(&list, item);
og_vector_ptr_destroy_all(&list); /* og_vector_destroy(item), then og_free(item) */
vector_ptr_size#
Unit tests
Count of slots in a pointer vector.
og_int_t og_vector_ptr_size(const og_vector_ptr_t *v);
NULL slots count as elements.
- Parameters
vThe pointer vector.
- Returns
- The size.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_size- In notebooks
Og.Native.og_vector_ptr_size- igraph 1.0
igraph_vector_ptr_size- See also
vector_ptr_capacity
vector_ptr_capacity#
Unit tests
The number of pointers the allocated storage can hold.
og_int_t og_vector_ptr_capacity(const og_vector_ptr_t *v);
Never below the size.
- Parameters
vThe pointer vector.
- Returns
- The capacity.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_capacity- In notebooks
Og.Native.og_vector_ptr_capacity- igraph 1.0
igraph_vector_ptr_capacity- See also
vector_ptr_reserve
vector_ptr_clear#
Unit tests
Removes all elements, running the item destructor on each one that is not NULL.
void og_vector_ptr_clear(og_vector_ptr_t *v);
The size becomes 0 and the storage is kept. The elements' own memory is not freed.
- Parameters
vThe pointer vector.
- Returns
- Nothing.
- Complexity
- O(n) destructor calls.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_clear- In notebooks
Og.Native.og_vector_ptr_clear- igraph 1.0
igraph_vector_ptr_clear- See also
vector_ptr_free_all,vector_ptr_resize
vector_ptr_reserve#
Unit tests
Makes room for at least capacity pointers without changing the size.
og_error_t og_vector_ptr_reserve(og_vector_ptr_t *v, og_int_t capacity);
Never shrinks the storage.
- Parameters
vThe pointer vector.capacityNumber of pointers to make room for.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated; the vector is left as it was.
- Complexity
- O(n) when the storage moves, otherwise O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_reserve- In notebooks
Og.Native.og_vector_ptr_reserve- igraph 1.0
igraph_vector_ptr_reserve- See also
vector_ptr_capacity
vector_ptr_resize#
Unit tests
Changes the number of elements of a pointer vector.
og_error_t og_vector_ptr_resize(og_vector_ptr_t *v, og_int_t new_size);
New slots are NULL. Shrinking runs no destructor: the dropped pointers are simply forgotten, so release them first if the vector owns them.
- Parameters
vThe pointer vector.new_sizeNew number of elements, 0 or more.
- Returns
OG_SUCCESS, or the error code.- Errors
OG_EINVALnew_size is negative.OG_ENOMEMMemory could not be allocated; the vector is left as it was.
- Complexity
- O(1) amortised per added element.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_resize- In notebooks
Og.Native.og_vector_ptr_resize- igraph 1.0
igraph_vector_ptr_resize- See also
vector_ptr_clear
vector_ptr_resize_min#
Unit tests
Releases unused storage: the capacity becomes equal to the size.
void og_vector_ptr_resize_min(og_vector_ptr_t *v);
Cannot fail: if the smaller block cannot be obtained the vector keeps its larger one.
- Parameters
vThe pointer vector.
- Returns
- Nothing.
- Complexity
- O(n) when the storage moves.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_resize_min- In notebooks
Og.Native.og_vector_ptr_resize_min- igraph 1.0
igraph_vector_ptr_resize_min- See also
vector_ptr_reserve
vector_ptr_push_back#
Unit tests
Appends one pointer.
og_error_t og_vector_ptr_push_back(og_vector_ptr_t *v, void *e);
Amortised O(1); on OG_ENOMEM the vector is unchanged. The vector does not take ownership of the object unless you give it an item destructor or release it with vector_ptr_destroy_all.
- Parameters
vThe pointer vector.eThe pointer.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated; the vector is left as it was.
- Complexity
- O(1) amortised.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_push_back- In notebooks
Og.Native.og_vector_ptr_push_back- igraph 1.0
igraph_vector_ptr_push_back- See also
vector_ptr_pop_back,vector_ptr_insert
vector_ptr_pop_back#
Unit tests
Takes the final pointer off the vector and hands it back.
void *og_vector_ptr_pop_back(og_vector_ptr_t *v);
The vector must not be empty (fatal error otherwise). No destructor runs: the object is handed to the caller.
- Parameters
vThe pointer vector.
- Returns
- The removed pointer.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_pop_back- In notebooks
Og.Native.og_vector_ptr_pop_back- igraph 1.0
igraph_vector_ptr_pop_back- See also
vector_ptr_push_back
vector_ptr_insert#
Unit tests
Inserts a pointer at a position, moving the later ones one place to the right.
og_error_t og_vector_ptr_insert(
og_vector_ptr_t *v,
og_int_t pos,
void *value
);
pos may be 0 .. size; pos == size appends.
- Parameters
vThe pointer vector.posPosition of the new pointer.valueThe pointer.
- Returns
OG_SUCCESS, or the error code.- Errors
OG_EINVALpos is outside 0 .. size.OG_ENOMEMMemory could not be allocated; the vector is left as it was.
- Complexity
- O(n - pos) amortised.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_insert- In notebooks
Og.Native.og_vector_ptr_insert- igraph 1.0
igraph_vector_ptr_insert- See also
vector_ptr_push_back
vector_ptr_get#
Unit tests
Reads one pointer.
void *og_vector_ptr_get(const og_vector_ptr_t *v, og_int_t pos);
Positions are not checked: staying inside 0 .. size - 1 is the caller's job.
- Parameters
vThe pointer vector.posPosition.
- Returns
- The pointer.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_get- In notebooks
Og.Native.og_vector_ptr_get- igraph 1.0
igraph_vector_ptr_get- See also
vector_ptr_set
vector_ptr_set#
Unit tests
Stores a pointer at a position.
void og_vector_ptr_set(og_vector_ptr_t *v, og_int_t pos, void *value);
The previous pointer is overwritten without running the item destructor. Positions are not checked: staying inside 0 .. size - 1 is the caller's job.
- Parameters
vThe pointer vector.posPosition.valueThe pointer.
- Returns
- Nothing.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_set- In notebooks
Og.Native.og_vector_ptr_set- igraph 1.0
igraph_vector_ptr_set- See also
vector_ptr_get
vector_ptr_sort#
Unit tests
Sorts the pointers with a comparison function.
void og_vector_ptr_sort(
og_vector_ptr_t *v,
int (*compar)(const void *, const void *)
);
compar receives pointers to two slots (for a vector of vector_t * it receives vector_t ** values, the form vector_lex_cmp_untyped expects) and returns a negative, zero or positive number. The sort is a stable bottom-up merge sort. If no memory is available for its buffer it merges in place by block rotations instead and gives the same order, so it cannot fail. The C library's qsort is never used, so the order is the same on every platform.
- Parameters
vThe pointer vector.comparComparison of two slots.
- Returns
- Nothing.
- Complexity
- O(n log n); O(n log^2 n) when merging in place.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_sort- In notebooks
Og.Native.og_vector_ptr_sort- igraph 1.0
igraph_vector_ptr_sort- See also
vector_ptr_sort_ind,vector_lex_cmp_untyped
vector_ptr_sort_ind#
Unit tests
The permutation that sorts a pointer vector by a comparison function.
og_error_t og_vector_ptr_sort_ind(
og_vector_ptr_t *v,
og_vector_int_t *inds,
og_cmp_t *cmp
);
inds is resized to v's size and receives positions in sorted order. Stable: equal elements keep their index order. Unlike vector_ptr_sort, cmp receives the stored pointers themselves, not pointers to slots. og_cmp_t is int (const void *, const void *).
- Parameters
vThe pointer vector.indsInitialised integer vector for the positions.cmpComparison of two stored pointers.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated.
- Complexity
- O(n log n).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_sort_ind- In notebooks
Og.Native.og_vector_ptr_sort_ind- igraph 1.0
igraph_vector_ptr_sort_ind- See also
vector_ptr_sort,vector_sort_ind
vector_ptr_permute#
Unit tests
Reorders a pointer vector by an index vector: position i receives the old element index[i].
og_error_t og_vector_ptr_permute(
og_vector_ptr_t *v,
const og_vector_int_t *index
);
An index vector shorter than v keeps only the pointers it names; the others are dropped without running the item destructor. Indices are not checked.
- Parameters
vThe pointer vector.indexFor each new position, the old position.
- Returns
OG_SUCCESS, orOG_ENOMEM.- Errors
OG_ENOMEMMemory could not be allocated; the vector is left as it was.
- Complexity
- O(k) for k indices.
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_permute- In notebooks
Og.Native.og_vector_ptr_permute- igraph 1.0
igraph_vector_ptr_permute- See also
vector_permute
vector_ptr_get_item_destructor#
Unit tests
Reports which function, if any, runs on elements when they are destroyed.
og_finally_func_t *og_vector_ptr_get_item_destructor(
const og_vector_ptr_t *v
);
NULL when none is set.
- Parameters
vThe pointer vector.
- Returns
- The destructor, or NULL.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_get_item_destructor- In notebooks
Og.Native.og_vector_ptr_get_item_destructor- igraph 1.0
igraph_vector_ptr_get_item_destructor- See also
vector_ptr_set_item_destructor
vector_ptr_set_item_destructor#
Unit tests
Sets the function that destroy, clear and free_all run on each element.
og_finally_func_t *og_vector_ptr_set_item_destructor(
og_vector_ptr_t *v,
og_finally_func_t *func
);
Returns the previous destructor; NULL removes it. The destructor takes the element pointer (og_finally_func_t is void (void *)). The macro OG_VECTOR_PTR_SET_ITEM_DESTRUCTOR(v, fn) does the cast for a typed destructor such as vector_destroy.
- Parameters
vThe pointer vector.funcThe destructor, or NULL.
- Returns
- The previous destructor.
- Complexity
- O(1).
- Checked
- python-igraph has no vector API, so there is no igraph oracle. Checked by unit tests; independent verifiers' seeded random tests against naive references; a verifier pass over the bool, char and pointer instantiations; random operation sequences replayed on plain C arrays with injected allocation failures.
- C name
og_vector_ptr_set_item_destructor- In notebooks
Og.Native.og_vector_ptr_set_item_destructor- igraph 1.0
igraph_vector_ptr_set_item_destructor- See also
vector_ptr_get_item_destructor,vector_ptr_destroy_all