Did you know ... Search Documentation:
Pack dynworks -- prolog/dynvector_core.pl
PublicShow source

This module provides an implementation of dynvectors. These are their noteworthy characteristics:

1. dynvectors are powerful, flexible, extendable, high-performance,
   hash-based vectors;
2. dynvectors have O(1) read/insert/update/delete times, and this holds
   true up to sizes in the order of millions of cells;<
3. dynvectors are not immutable objects, or more specifically, they are not
   recreated upon modification;
4. dynvectors have no limitation on the number of cells, apart from the
   running platform's resource limitations;
5. dynvectors do not have a maximum number of cells specified at creation time -
   elements may be freely inserted, updated, or deleted, as the dynvector
   dynamically adjusts its upper bound as needed;
6. dynvectors demand no storage space reservation previous to the actual
   cell-by-cell space allocation requests;
7. dynvectors are resource-minded; their cells are not required to have values
   assigned to, in any particular sequence or fashion;
8. in order to avoid resource wastage, dynvectors should be explicitly
   destroyed, upon ceasing to be of any further use.
author
- GT Nunes
version
- 1.3.2
license
- BSD-3-Clause License
 dynvector_create(+Id:atom) is semidet
Create a dynvector.
Arguments:
Id- Atom identifying the dynvector
 dynvector_destroy(+Id:atom)
Destroy dynvector Id, and release all of its resources. No action if it does not exist.
Arguments:
Id- Atom identifying the dynvector
 is_dynvector(+Id:atom) is semidet
Fail if Id does not identify a dynvector.
Arguments:
Id- Atom identifying the dynvector
 dynvector_version(-Version:number) is det
Unify Version with the current version of the dynvector implementation.
Arguments:
Version- Dynvector implementation's current version
 dynvector_top(+Id:atom, -Top:int) is semidet
Unify Top with the highest inserted index value in the dynvector, even if it has subsequently been deleted. Upon dynvector's creation, this value is set to -1.
Arguments:
Id- Atom identifying the dynvector
Top- Value of the highest index
 dynvector_value(+Id:atom, +Index:int, ?Value:data) is semidet
Unify Value with the value of the dynvector cell at Index. Dynvectors may be sparsed, i.e., they may have cells not holding values, but attempts to retrieve the value of an empty cell will fail. Dynvector values are stored in the dynamic predicate dynvect_vaLues(Position, Id, Value).
Arguments:
Id- Atom identifying the dynvector
Index- The reference index, or a label standing for it
Value- The dynvector cell value
 dynvector_label(+Id:atom, +Label:atom, ?Value:Data) is semidet
Unify Value with the value associated with Label. This allows atoms to stand for indices. Label values are stored in the dynamic predicate dynvect_labels(Id, Label, Value).

The following are the read-only private labels in use:

dv_top   - maximum index value in the dynvector
dv_first - begin index for iterator
dv_last  - end index for iterator
dv_curr  - current index for iterator
Arguments:
Id- atom identifying the dynvector
Label- atom standing for the named attribute
Value- associated with the named attribute
 dynvector_find(+Id:atom, ?Index:int, ?Value:data) is semidet
Unify Index or Value with an occurrence of Index or Value in the dynvector, respectively. Fail if no such value or index exist.
Arguments:
Id- Atom identifying the dynvector
Index- The reference index
Value- The reference value
 dynvector_append(+Id:atom, +Value:data, -Index:int) is det
Append the given Value to the dynvector, and unify Index with the appension position. Value may be scalar, a list, or another dynvector.
Arguments:
Id- Atom identifying the dynvector
Value- Value or list of of values to append
Index- Index identifying the element holding Value or its first element
 dynvector_insert(+Id:atom, +Index:int, +Value:data)
Insert Value into the dynvector at Index. Value may be scalar, a list, or another dynvector.
Arguments:
Id- Atom identifying the dynvector
Index- The insertion point
Value- Value or list of of values to insert
 dynvector_delete(+Id:atom, +Index) is semidet
Erase the dynvector cell at Index, releasing the storage space taken. Fail if no such cell exists.
Arguments:
Id- Atom identifying the dynvector
Index- The reference index, or a label standing for it
 dynvector_list(+Id:atom, ?List:list) is det
Unify the cells of the dynvector with the values in List. A dynvector to hold all the list elements may be created. Note that this is not a serialization a mechanism, and as such it should not be used for backup/restore purposes.
Arguments:
Id- Atom identifying the dynvector
List- List of values to unify the dynvector cells with
 dynvector_fill(+Id:atom, +Value:data) is det
Unify all of the cells of the dynvector with Value.
Arguments:
Id- Atom identifying the dynvector
Value- Value to unify the dynvector cells with
 dynvector_sort(+Id:atom) is det
Numerically sort the contents of the dynvector, in ascending order. It must be possible to numerically compare any two elements stored in the dynvector. In the case of a sparse dynvector, the empty cells are ignored. Nothing is done if the dynvector contains less than two elements. Depending on the volume and nature of the data stored, this may be a very expensive operation, in terms of memory and/or time consumed.<br/>
Arguments:
Id- Atom identifying the dynarray
 dynvector_sort(+Id:atom, :Comparator:pred) is det
Sort the contents of the dynvector according to the given comparison predicate. The comparison predicate must accept two parameters, ValueX and ValueY, and have the following behavior:
<Comparator>(+ValueX, +ValueY, -Result:number) is det
where Result is unified with
  a) 0 (zero)          - ValueX is equal to ValueY
  b) a negative number - ValueX is less than ValueY
  c) a positive number - ValueX is greater than ValueY

The criteria that will determine the results of the comparisons are entirely up to Comparator, and as such it must be able to handle all the values it receives.
In the case of a sparse dynvector, the empty cells are ignored. Nothing is done if the dynvector contains less than two elements. Depending on the volume and nature of the data stored, this may be a very expensive operation, in terms of memory and/or time consumed.<br/>

Arguments:
Id- Atom identifying the dynvector
Comparator- Predicate to perform comparisons between two values
 dynvector_iterator_create(+Id:atom) is semidet
Create iterator with range from 0 to Top.
Arguments:
Id- Atom identifying the dynvector
 dynvector_iterator_create(+Id:atom, +From:int) is semidet
Create iterator with range from From to Top.
Arguments:
Id- Atom identifying the dynvector
From- The iterator's first index
 dynvector_iterator_create(+Id:atom, +From:int, +To:int) is semidet
Create iterator with range from From to To. Initial and final range positions must be consistent with the dynvector state. Fail if the dynvector already has an active iterator.
Arguments:
Id- Atom identifying the dynvector
From- The iterator's first index
To- The iterator's last index
 dynvector_iterator_destroy(+Id:atom) is semidet
Destroy the dynvector's iterator. Fail if dynvector Id does not exist. No action if dynvector does not have an active iterator.
Arguments:
Id- Atom identifying the dynvector
 dynvector_iterator_next(+Id:atom, ?Value:data) is semidet
Move the itrator to the next position, and unify Value with the value therein. Fail if dynvector does not have an active iterator, or if a next position is not possible.
Arguments:
Id- Atom identifying the dynvector
Value- Value to unify the iterator's next position with
 dynvector_iterator_prev(+Id:atom, ?Value:data) is semidet
Move the iterator to the previous position, and unify Value with the value therein. Fail if dynvector does not have an active iterator, or if a previous position is not possible.
Arguments:
Id- Atom identifying the dynvector
Value- Value to unify the iterator's previous position with
 dynvector_iterator_first(+Id:atom, ?Value:data) is semidet
Move the iterator to the first position, and unify Value with the value therein. Fail if dynvector does not have an active iterator.
Arguments:
Id- Atom identifying the dynvector
Value- Value to unify the iterator's first position with
 dynvector_iterator_last(+Id:atom, ?Value:data) is semidet
Move the iterator to the last position, and unify Value with the value therein. Fail if dynvector does not have an active iterator.
Arguments:
Id- Atom identifying the dynvector
Value- Value to unify the iterator's last position with
 dynvector_iterator_current(+Id:atom, ?Value) is semidet
Unify Value with the value at iterator's current position. Fail if dynvector does not have an active iterator.
Arguments:
Id- Atom identifying the dynvector
Value- Value to unify the iterator's current position with
 dynvector_iterator_delete(+Id:atom) is semidet
Erase value at iterator's current position. Fail if dynvector does not have an active iterator.
Arguments:
Id- Atom identifying the dynvector
 dynvector_iterator_index(+Id:atom, -Index:int) is semidet
Unify Index with iterator's current index.
Arguments:
Id- Atom identifying the dynvector
Index- The iterator's current index
 dynvector_iterator_insert(+Id:atom, ?Value:data) is semidet
Insert Value at iterator's current position, and adjust the iterator's range accordingly. Fail if dynvector does not have an active iterator.
Arguments:
Id- Atom identifying the dynvector
Value- Value to be inserted
 dynvector_iterator_append(+Id:atom, ?Value)
Insert Value after iterator's last position, and adjust the iterator's range accordingly. Fail if dynvector does not have an active iterator.
Arguments:
Id- Atom identifying the dynvector
Value- Value to be appended