Home Reference Source
import {Iterator} from 'jstreemap/src/public/iterators.js'
public class | source

Iterator

Extends:

BaseIterator → Iterator

STL-like forward iterator. It's more verbose than ES6 iterators, but allows iteration over any part of the container

Example:

let m = new TreeMap();
...
for (let it = m.begin(); !it.equals(m.end()); it.next()) {
  console.log(`key: ${it.key}, value: ${it.value}`);
}

Constructor Summary

Public Constructor
public

constructor(args: *)

There are 3 ways to construct an iterator:

Method Summary

Public Methods
public

next()

Replaces node reference with the reference of the next node in the container.

public

prev()

Replaces node reference with the reference of the previous node in the container Can be used for manual reverse iteration over a range of key-value pairs.

Inherited Summary

From class BaseIterator
public

Two iterators are considered to be equal if they point to the same node of the same container

Public Constructors

public constructor(args: *) source

There are 3 ways to construct an iterator:

  1. Using a node and a container
  2. Copy constructor / clone
  3. Copy constructor / clone from ReverseIterator instance

Override:

BaseIterator#constructor

Params:

NameTypeAttributeDescription
args *

Example:

// Using a node and a container
let it = new Iterator(node, container);

// Copy constructor / clone
let it1 = new Iterator(node, container);
let it2 = new Iterator(it1);

// Copy constructor / clone from ReverseIterator instance
let it1 = new ReverseIterator(node, container);
let it2 = new Iterator(it1);

Public Methods

public next() source

Replaces node reference with the reference of the next node in the container. Can be used for manual iteration over a range of key-value pairs.

Example:

let m = new TreeMap();
... // add key-value pairs., using numbers as keys
let from = t.lowerBound(0);
let to = t.upperBound(50);
let it = from;
while (!it.equals(to)) {
  console.log(it.key);
  it.next();
}

public prev() source

Replaces node reference with the reference of the previous node in the container Can be used for manual reverse iteration over a range of key-value pairs.

Example:

let m = new TreeMap();
... // add key-value pairs., using numbers as keys
let from = t.lowerBound(0);
let to = t.upperBound(50);
let it = to;
while (!it.equals(from)) {
  it.prev();
  console.log(it.key);
}