Next: Unordered-set functions, Previous: Task-mapping functions, Up: Run-time library functions [Contents][Index]
Because queues are a widely applicable construct, the run-time library provides support for queues of arbitrary datatypes. In the current implementation, these can more precisely be termed “dynamically growing lists” than “queues”. However, they may be extended in a future version of the library to support more queue-like functionality.
ncptl_queue_init()
creates and initializes a dynamically growing queue in
which each element occupies eltbytes bytes of
memory.
Allocate a new data element at the end of queue
queue. The queue passed to ncptl_queue_allocate()
must
be one returned by ncptl_queue_init()
.
ncptl_queue_allocate()
returns a pointer to the data element allocated.
Push (via a memory copy) the element pointed to by
element onto the end of queue queue and
return a pointer to the copy in the queue. The queue passed to
ncptl_queue_allocate()
must
be one returned by ncptl_queue_init()
.
( ncptl_queue_push()
is actually implemented in terms of ncptl_queue_allocate()
.)
Push (via a memory copy) all of the elements in
source_queue onto the end of target_queue. A
fatal error will occur if the two queues were not initialized with
the same eltbytes argument to ncptl_queue_init()
.
ncptl_queue_push_all()
does
not modify source_queue.
Pop a pointer to the element at the head of queue
queue. If queue is empty, return
NULL
. The pointer returned by ncptl_queue_pop()
is
guaranteed to be valid until the next invocation of ncptl_queue_empty()
.
Pop a pointer to the element at the tail of queue
queue. If queue is empty, return
NULL
. In essence, this lets the caller treat the queue
as a stack. The pointer returned by ncptl_queue_pop_tail()
is
guaranteed to be valid until the next invocation of ncptl_queue_empty()
,
ncptl_queue_allocate()
or
ncptl_queue_push()
.
Return queue queue as an array of elements. If
ncptl_queue_contents()
is
passed ‘1’ for copyelts, a new array is
allocated using ncptl_malloc()
; the queue’s
internal array is copied to the newly allocated array; and, this
new array is returned to the caller. It is the caller’s
responsibility to pass the result to
ncptl_free()
when the array is no longer needed. If ncptl_queue_contents()
is
passed ‘0’ for copyelts, a pointer to the
queue’s internal array is returned without first copying it. This
pointer should not be passed to ncptl_free()
as it is still
needed by queue.
Return the number of elements in queue queue.
Empty a queue, freeing the memory that had been allocated for
its elements. Queue contents returned by ncptl_queue_contents()
with copyelts set to ‘0’ are also
invalidated. The queue itself can continue to be used and should be
deallocated with ncptl_free()
(see
Memory-allocation functions) when no longer needed.
Next: Unordered-set functions, Previous: Task-mapping functions, Up: Run-time library functions [Contents][Index]