NAME

src/pmc/hashiterator.pmc - Implementation of Iterator for Hashes.

DESCRIPTION

Generic iterator for traversing Hash.

SYNOPSIS

default usage

    .local pmc iterator, hash, key, entry
    iterator = iter hash
  iter_loop:
    unless iterator, iter_end  # while (more values)
    key   = shift iterator     # get the key. Some key
    entry = hash[key]
    ...
    goto iter_loop
  iter_end:

C++-style usage

    .local pmc iterator, hash, iter_key, key, entry
    iterator = iter hash
  iter_loop:
    unless iterator, iter_end  # while (more values)
    iter_key = shift iterator     # get the key
    key = iter_key.'key'()        # get an original key used to put value
    key = iter_key.'value'()      # get an entry
    ...
    goto iter_loop
  iter_end:

Methods

void init_pmc(PMC *initializer)
Initializes the iterator with an aggregate PMC. Defaults iteration mode to iterate from start.
void destroy()
destroys this PMC
void mark()
Marks the hash as live.
PMC *clone()
void set_integer_native()
PMC *get_pmc()
Returns this Iterator's Hash.
INTVAL get_bool()
Returns true if there is more elements to iterate over.
INTVAL elements()
Returns the number of remaining elements in the Hash.
PMC *shift_pmc()
Returns the HashIteratorKey for the current position and advance the next one.