2.14.  Pointer vectors (igraph_vector_ptr_t)

2.14.1. igraph_vector_ptr_init — Initialize a pointer vector (constructor).
2.14.2. igraph_vector_ptr_copy — Copy a pointer vector (constructor).
2.14.3. igraph_vector_ptr_destroy — Destroys a pointer vector.
2.14.4. igraph_vector_ptr_size — Gives the number of elements in the pointer vector.
2.14.5. igraph_vector_ptr_clear — Removes all elements from a pointer vector.
2.14.6. igraph_vector_ptr_push_back — Appends an elements to the back of a pointer vector.
2.14.7. igraph_vector_ptr_e — Access an element of a pointer vector.
2.14.8. igraph_vector_ptr_set — Assign to an element of a pointer vector.
2.14.9. igraph_vector_ptr_resize — Resizes a pointer vector.

The igraph_vector_ptr_t data type is very similar to the igraph_vector_t type, but it stores generic pointers instead of real numbers.

This type has the same space complexity as igraph_vector_t, and most implemented operations work the same way as for igraph_vector_t.

This type is mostly used to pass to or receive from a set of graphs to some igraph functions, such as igraph_decompose(), which decomposes a graph to connected components.

The same VECTOR macro used for ordinary vectors can be used for pointer vectors as well, please note that a typeless generic pointer will be provided by this macro and you may need to cast it to a specific pointer before starting to work with it.

2.14.1. igraph_vector_ptr_init — Initialize a pointer vector (constructor).

int igraph_vector_ptr_init      (igraph_vector_ptr_t* v, int long size);

This is the constructor of the pointer vector data type. All pointer vectors constructed this way should be destroyed via calling igraph_vector_ptr_destroy().

Arguments: 

v:

Pointer to an uninitialized igraph_vector_ptr_t object, to be created.

size:

Integer, the size of the pointer vector.

Returns: 

Error code: IGRAPH_ENOMEM if out of memory

Time complexity: operating system dependent, the amount of “time” required to allocate size elements.

2.14.2. igraph_vector_ptr_copy — Copy a pointer vector (constructor).

int igraph_vector_ptr_copy(igraph_vector_ptr_t *to, const igraph_vector_ptr_t *from);

This function creates a pointer vector by copying another one. This is shallow copy, only the pointers in the vector will be copyed.

Arguments: 

to:

Pointer to an uninitialized pointer vector object.

from:

A pointer vector object.

Returns: 

Error code: IGRAPH_ENOMEM if out of memory

Time complexity: O(n) if allocating memory for n elements can be done in O(n) time.

2.14.3. igraph_vector_ptr_destroy — Destroys a pointer vector.

void igraph_vector_ptr_destroy   (igraph_vector_ptr_t* v);

The destructor for pointer vectors.

Arguments: 

v:

Pointer to the pointer vector to destroy.

Time complexity: operating system dependend, the “time” required to deallocate O(n) bytes, n is the number of elements allocated for the pointer vector (not neccessarily the number of elements in the vector).

2.14.4. igraph_vector_ptr_size — Gives the number of elements in the pointer vector.

long int igraph_vector_ptr_size      (const igraph_vector_ptr_t* v);

Arguments: 

v:

The pointer vector object.

Returns: 

The size of the object, ie. the number of pointers stored.

Time complexity: O(1).

2.14.5. igraph_vector_ptr_clear — Removes all elements from a pointer vector.

void igraph_vector_ptr_clear     (igraph_vector_ptr_t* v);

This function resizes a pointer to vector to zero length. Note that the pointed objects are not deallocated, you should call free() on them, or make sure that their allocated memory is freed in some other way, you'll get memory leaks otherwise.

Note that the current implementation of this function does not deallocate the memory required for storing the pointers, so making a pointer vector smaller this way does not give back any memory. This behavior might change in the future.

Arguments: 

v:

The pointer vector to clear.

Time complexity: O(1).

2.14.6. igraph_vector_ptr_push_back — Appends an elements to the back of a pointer vector.

int igraph_vector_ptr_push_back (igraph_vector_ptr_t* v, void* e);

Arguments: 

v:

The pointer vector.

e:

The new element to include in the pointer vector.

Returns: 

Error code.

See also: 

igraph_vector_push_back() for the corresponding operation of the ordinary vector type.

Time complexity: O(1) or O(n), n is the number of elements in the vector. The pointer vector implementation ensures that n subsequent push_back operations need O(n) time to complete.

2.14.7. igraph_vector_ptr_e — Access an element of a pointer vector.

void* igraph_vector_ptr_e         (const igraph_vector_ptr_t* v, long int pos);

Arguments: 

v:

Pointer to a pointer vector.

pos:

The index of the pointer to return.

Returns: 

The pointer at pos position.

Time complexity: O(1).

2.14.8. igraph_vector_ptr_set — Assign to an element of a pointer vector.

void igraph_vector_ptr_set       (igraph_vector_ptr_t* v, long int pos, void* value);

Arguments: 

v:

Pointer to a pointer vector.

pos:

The index of the pointer to update.

value:

The new pointer to set in the vector.

Time complexity: O(1).

2.14.9. igraph_vector_ptr_resize — Resizes a pointer vector.

int igraph_vector_ptr_resize(igraph_vector_ptr_t* v, long int newsize);

Note that if a vector is made smaller the pointed object are not deallocated by this function.

Arguments: 

v:

A pointer vector.

newsize:

The new size of the pointer vector.

Returns: 

Error code.

Time complexity: O(1) if the vector if made smaller. Operating system dependent otherwise, the amount of “time” needed to allocate the memory for the vector elements.