*/
public abstract class Gee.AbstractCollection<G> : Object, Iterable<G>, Collection<G> {
- //
- // Inherited from Collection<G>
- //
-
+ /**
+ * @inheritDoc
+ */
public abstract int size { get; }
+ /**
+ * @inheritDoc
+ */
public virtual bool is_empty {
get { return size == 0; }
}
+ /**
+ * @inheritDoc
+ */
public abstract bool contains (G item);
+ /**
+ * @inheritDoc
+ */
public abstract bool add (G item);
+ /**
+ * @inheritDoc
+ */
public abstract bool remove (G item);
+ /**
+ * @inheritDoc
+ */
public abstract void clear ();
+ /**
+ * @inheritDoc
+ */
public virtual G[] to_array() {
G[] array = new G[size];
int index = 0;
return array;
}
+ /**
+ * @inheritDoc
+ */
public virtual bool add_all (Collection<G> collection) {
if (collection.is_empty) {
return false;
return changed;
}
+ /**
+ * @inheritDoc
+ */
public virtual bool contains_all (Collection<G> collection) {
if (collection.size > size) {
return false;
return true;
}
+ /**
+ * @inheritDoc
+ */
public virtual bool remove_all (Collection<G> collection) {
bool changed = false;
foreach (G item in collection) {
return changed;
}
+ /**
+ * @inheritDoc
+ */
public virtual bool retain_all (Collection<G> collection) {
bool changed = false;
G[] items = to_array ();
return changed;
}
- //
- // Inherited from Iterable<G>
- //
-
+ /**
+ * @inheritDoc
+ */
public Type element_type {
get { return typeof (G); }
}
+ /**
+ * @inheritDoc
+ */
public abstract Iterator<G> iterator ();
}
*/
public abstract class Gee.AbstractList<G> : Gee.AbstractCollection<G>, List<G> {
+ /**
+ * @inheritDoc
+ */
public abstract new G? get (int index);
+ /**
+ * @inheritDoc
+ */
public abstract new void set (int index, G item);
+ /**
+ * @inheritDoc
+ */
public abstract int index_of (G item);
+ /**
+ * @inheritDoc
+ */
public abstract void insert (int index, G item);
+ /**
+ * @inheritDoc
+ */
public abstract void remove_at (int index);
+ /**
+ * @inheritDoc
+ */
public abstract List<G>? slice (int start, int stop);
+ /**
+ * @inheritDoc
+ */
public virtual G? first () {
return get (0);
}
+ /**
+ * @inheritDoc
+ */
public virtual G? last () {
return get (size - 1);
}
+ /**
+ * @inheritDoc
+ */
public virtual void insert_all (int index, Collection<G> collection) {
foreach (G item in collection) {
insert(index, item);
*/
public abstract class Gee.AbstractMap<K,V> : Object, Map<K,V> {
+ /**
+ * @inheritDoc
+ */
public abstract int size { get; }
+ /**
+ * @inheritDoc
+ */
public virtual bool is_empty {
get { return size == 0; }
}
+ /**
+ * @inheritDoc
+ */
public abstract Set<K> get_keys ();
+ /**
+ * @inheritDoc
+ */
public abstract Collection<V> get_values ();
+ /**
+ * @inheritDoc
+ */
public abstract bool contains (K key);
+ /**
+ * @inheritDoc
+ */
public abstract new V? get (K key);
+ /**
+ * @inheritDoc
+ */
public abstract new void set (K key, V value);
+ /**
+ * @inheritDoc
+ */
public abstract bool remove (K key, out V? value = null);
+ /**
+ * @inheritDoc
+ */
public abstract void clear ();
+ /**
+ * @inheritDoc
+ */
public virtual void set_all (Map<K,V> map) {
foreach (K key in map.get_keys ()) {
set (key, map.get (key));
}
}
+ /**
+ * @inheritDoc
+ */
public virtual bool remove_all (Map<K,V> map) {
bool changed = false;
foreach (K key in map.get_keys ()) {
return changed;
}
+ /**
+ * @inheritDoc
+ */
public virtual bool contains_all (Map<K,V> map) {
foreach (K key in map.get_keys ()) {
if (!contains (key)) {
// concurrent modification protection
private int _stamp = 0;
+ /**
+ * Array list implementation constructor.
+ *
+ * @param equal_func an optional elements equality testing function.
+ */
public ArrayList (EqualFunc? equal_func = null) {
if (equal_func == null) {
equal_func = Functions.get_equal_func_for (typeof (G));
this.equal_func = equal_func;
}
+ /**
+ * @inheritDoc
+ */
public override Gee.Iterator<G> iterator () {
return new Iterator<G> (this);
}
+ /**
+ * @inheritDoc
+ */
public override bool contains (G item) {
return (index_of (item) != -1);
}
+ /**
+ * @inheritDoc
+ */
public override int index_of (G item) {
for (int index = 0; index < _size; index++) {
if (equal_func (_items[index], item)) {
return -1;
}
+ /**
+ * @inheritDoc
+ */
public override G? get (int index) {
assert (index >= 0);
assert (index < _size);
return _items[index];
}
+ /**
+ * @inheritDoc
+ */
public override void set (int index, G item) {
assert (index >= 0);
assert (index < _size);
_items[index] = item;
}
+ /**
+ * @inheritDoc
+ */
public override bool add (G item) {
if (_size == _items.length) {
grow_if_needed (1);
return true;
}
+ /**
+ * @inheritDoc
+ */
public override void insert (int index, G item) {
assert (index >= 0);
assert (index <= _size);
_stamp++;
}
+ /**
+ * @inheritDoc
+ */
public override bool remove (G item) {
for (int index = 0; index < _size; index++) {
if (equal_func (_items[index], item)) {
return false;
}
+ /**
+ * @inheritDoc
+ */
public override void remove_at (int index) {
assert (index >= 0);
assert (index < _size);
_stamp++;
}
+ /**
+ * @inheritDoc
+ */
public override void clear () {
for (int index = 0; index < _size; index++) {
_items[index] = null;
_stamp++;
}
+ /**
+ * @inheritDoc
+ */
public override List<G>? slice (int start, int stop) {
return_val_if_fail (start <= stop, null);
return_val_if_fail (start >= 0, null);
return slice;
}
+ /**
+ * @inheritDoc
+ */
public override bool add_all (Collection<G> collection) {
if (collection.is_empty) {
return false;
return true;
}
+ /**
+ * @inheritDoc
+ */
public override bool remove_all (Collection<G> collection) {
bool changed = false;
for (int index = 0; index < _size; index++) {
return changed;
}
+ /**
+ * @inheritDoc
+ */
public override bool retain_all (Collection<G> collection) {
bool changed = false;
for (int index = 0; index < _size; index++) {
public class Functions {
+ /**
+ * Get a equality testing function for a given type.
+ *
+ * @param t the type which to get an equality testing function for.
+ *
+ * @return the equality testing function corresponding to the given type.
+ */
public static EqualFunc get_equal_func_for (Type t) {
if (t == typeof (string)) {
return str_equal;
}
}
+ /**
+ * Get a hash function for a given type.
+ *
+ * @param t the type which to get the hash function for.
+ *
+ * @return the hash function corresponding to the given type.
+ */
public static HashFunc get_hash_func_for (Type t) {
if (t == typeof (string)) {
return str_hash;
}
}
+ /**
+ * Get a comparator function for a given type.
+ *
+ * @param t the type which to get a comparator function for.
+ *
+ * @return the comparator function corresponding to the given type.
+ */
public static CompareFunc get_compare_func_for (Type t) {
if (t == typeof (string)) {
return (CompareFunc) strcmp;
}
}
+ /**
+ * Compares to arbitrary elements together.
+ *
+ * The comparison is done on pointers and not on values behind.
+ *
+ * @param _val1 the first value to compare.
+ * @param _val2 the second value to compare.
+ *
+ * @return a negative value if _val1 is lesser than _val2, a positive value
+ * if _val1 is greater then _val2 and zero if both are equal.
+ */
public static int direct_compare (void* _val1, void* _val2) {
long val1 = (long)_val1, val2 = (long)_val2;
if (val1 > val2) {
get { return _nnodes; }
}
+ /**
+ * Hash function.
+ */
public HashFunc hash_func { private set; get; }
+ /**
+ * Equality testing function.
+ */
public EqualFunc equal_func { private set; get; }
private int _array_size;
private const int MIN_SIZE = 11;
private const int MAX_SIZE = 13845163;
+ /**
+ * Hash set implementation constructor.
+ *
+ * @param hash_func an optional hash function.
+ * @param equal_func an optional equality testing function.
+ */
public HashSet (HashFunc? hash_func = null, EqualFunc? equal_func = null) {
if (hash_func == null) {
hash_func = Functions.get_hash_func_for (typeof (G));
return node;
}
+ /**
+ * @inheritDoc
+ */
public override bool contains (G key) {
Node<G>** node = lookup_node (key);
return (*node != null);
}
+ /**
+ * @inheritDoc
+ */
public override Gee.Iterator<G> iterator () {
return new Iterator<G> (this);
}
+ /**
+ * @inheritDoc
+ */
public override bool add (G key) {
Node<G>** node = lookup_node (key);
if (*node != null) {
}
}
+ /**
+ * @inheritDoc
+ */
public override bool remove (G key) {
Node<G>** node = lookup_node (key);
if (*node != null) {
return false;
}
+ /**
+ * @inheritDoc
+ */
public override void clear () {
for (int i = 0; i < _array_size; i++) {
Node<G> node = (owned) _nodes[i];
private Node? _head = null;
private Node? _tail = null;
+ /**
+ * Equality testing between elements function.
+ */
public EqualFunc equal_func { private set; get; }
+ /**
+ * Linked list implementation constructor.
+ *
+ * @param equal_func an optional equality testing function.
+ */
public LinkedList (EqualFunc? equal_func = null) {
if (equal_func == null) {
equal_func = Functions.get_equal_func_for (typeof (G));
this.equal_func = equal_func;
}
- // Iterable<G>
+ /**
+ * @inheritDoc
+ */
public override Gee.Iterator<G> iterator () {
return new Iterator<G> (this);
}
- // Collection<G>
+ /**
+ * @inheritDoc
+ */
public override int size {
get { return this._size; }
}
+ /**
+ * @inheritDoc
+ */
public override bool contains (G item) {
return this.index_of (item) != -1;
}
+ /**
+ * @inheritDoc
+ */
public override bool add (G item) {
Node<G> n = new Node<G> (item);
if (this._head == null && this._tail == null) {
return true;
}
+ /**
+ * @inheritDoc
+ */
public override bool remove (G item) { // Should remove only the first occurence (a test should be added)
for (Node<G> n = this._head; n != null; n = n.next) {
if (this.equal_func (item, n.data)) {
return false;
}
+ /**
+ * @inheritDoc
+ */
public override void clear () {
++this._stamp;
this._head = this._tail = null;
this._size = 0;
}
- // List<G>
+ /**
+ * @inheritDoc
+ */
public override G? get (int index) {
assert (index >= 0);
assert (index < this._size);
}
}
+ /**
+ * @inheritDoc
+ */
public override void set (int index, G item) {
assert (index >= 0);
assert (index < this._size);
n.data = item;
}
+ /**
+ * @inheritDoc
+ */
public override int index_of (G item) {
int result = -1;
int idx = 0;
return result;
}
+ /**
+ * @inheritDoc
+ */
public override void insert (int index, G item) {
assert (index >= 0);
assert (index <= this._size);
}
}
+ /**
+ * @inheritDoc
+ */
public override void remove_at (int index) {
assert (index >= 0);
assert (index < this._size);
this._remove_node (n);
}
+ /**
+ * @inheritDoc
+ */
public override List<G>? slice (int start, int stop) {
return_val_if_fail (start <= stop, null);
return_val_if_fail (start >= 0, null);
* Represents a read-only collection of items.
*/
public class Gee.ReadOnlyCollection<G> : Object, Iterable<G>, Collection<G> {
+
+ /**
+ * @inheritDoc
+ */
public int size {
get { return _collection.size; }
}
+ /**
+ * @inheritDoc
+ */
public bool is_empty {
get { return _collection.is_empty; }
}
+ /**
+ * Generic collection property.
+ */
public Collection<G> collection {
construct { _collection = value; }
}
private Collection<G> _collection;
+ /**
+ * Read only collection constructor.
+ *
+ * @param collection the collection to decorate (may be null).
+ */
public ReadOnlyCollection (Collection<G>? collection = null) {
this.collection = collection;
}
+ /**
+ * @inheritDoc
+ */
public Type element_type {
get { return typeof (G); }
}
+ /**
+ * @inheritDoc
+ */
public Gee.Iterator<G> iterator () {
if (_collection == null) {
return new Iterator<G> ();
return _collection.iterator ();
}
+ /**
+ * @inheritDoc
+ */
public bool contains (G item) {
if (_collection == null) {
return false;
return _collection.contains (item);
}
+ /**
+ * Unimplemented method (read only collection).
+ */
public bool add (G item) {
assert_not_reached ();
}
+ /**
+ * Unimplemented method (read only collection).
+ */
public bool remove (G item) {
assert_not_reached ();
}
+ /**
+ * Unimplemented method (read only collection).
+ */
public void clear () {
assert_not_reached ();
}
+ /**
+ * Unimplemented method (read only collection).
+ */
public bool add_all (Collection<G> collection) {
assert_not_reached ();
}
+ /**
+ * @inheritDoc
+ */
public bool contains_all (Collection<G> collection) {
foreach (G element in collection) {
if (!contains (element)) {
return true;
}
+ /**
+ * Unimplemented method (read only collection).
+ */
public bool remove_all (Collection<G> collection) {
assert_not_reached ();
}
+ /**
+ * Unimplemented method (read only collection).
+ */
public bool retain_all(Collection<G> collection) {
assert_not_reached ();
}
+ /**
+ * @inheritDoc
+ */
public G[] to_array() {
return _collection.to_array ();
}
* Represents a read-only collection of items in a well-defined order.
*/
public class Gee.ReadOnlyList<G> : Object, Iterable<G>, Collection<G>, List<G> {
+
+ /**
+ * @inheritDoc
+ */
public int size {
get { return _list.size; }
}
+ /**
+ * @inheritDoc
+ */
public bool is_empty {
get { return _list.is_empty; }
}
+ /**
+ * @inheritDoc
+ */
public List<G> list {
construct { _list = value; }
}
private List<G> _list;
+ /**
+ * Read only list implementation constrcutor.
+ *
+ * @param list the list to decorate (may be null).
+ */
public ReadOnlyList (List<G>? list = null) {
this.list = list;
}
+ /**
+ * @inheritDoc
+ */
public Type element_type {
get { return typeof (G); }
}
+ /**
+ * @inheritDoc
+ */
public Gee.Iterator<G> iterator () {
if (_list == null) {
return new Iterator<G> ();
return _list.iterator ();
}
+ /**
+ * @inheritDoc
+ */
public bool contains (G item) {
if (_list == null) {
return false;
return _list.contains (item);
}
+ /**
+ * @inheritDoc
+ */
public int index_of (G item) {
if (_list == null) {
return -1;
return _list.index_of (item);
}
+ /**
+ * Unimplemented method (read only list).
+ */
public bool add (G item) {
assert_not_reached ();
}
+ /**
+ * Unimplemented method (read only list).
+ */
public bool remove (G item) {
assert_not_reached ();
}
+ /**
+ * Unimplemented method (read only list).
+ */
public void insert (int index, G item) {
assert_not_reached ();
}
+ /**
+ * Unimplemented method (read only list).
+ */
public void remove_at (int index) {
assert_not_reached ();
}
+ /**
+ * @inheritDoc
+ */
public new G? get (int index) {
if (_list == null) {
return null;
return _list.get (index);
}
+ /**
+ * Unimplemented method (read only list).
+ */
public new void set (int index, G o) {
assert_not_reached ();
}
+ /**
+ * @inheritDoc
+ */
public void clear () {
assert_not_reached ();
}
+ /**
+ * Unimplemented method (read only list).
+ */
public List<G>? slice (int start, int stop) {
assert_not_reached ();
}
+ /**
+ * Unimplemented method (read only list).
+ */
public bool add_all (Collection<G> collection) {
assert_not_reached ();
}
+ /**
+ * @inheritDoc
+ */
public bool contains_all (Collection<G> collection) {
if (_list == null) {
return false;
return _list.contains_all (collection);
}
+ /**
+ * Unimplemented method (read only list).
+ */
public bool remove_all (Collection<G> collection) {
assert_not_reached ();
}
+ /**
+ * Unimplemented method (read only list).
+ */
public bool retain_all (Collection<G> collection) {
assert_not_reached ();
}
+ /**
+ * @inheritDoc
+ */
public G? first () {
if (_list == null) {
return null;
return _list.first ();
}
+ /**
+ * @inheritDoc
+ */
public G? last () {
if (_list == null) {
return null;
return _list.last ();
}
+ /**
+ * Unimplemented method (read only list).
+ */
public void insert_all (int index, Collection<G> collection) {
assert_not_reached ();
}
+ /**
+ * @inheritDoc
+ */
public G[] to_array() {
return _list.to_array ();
}
* Represents a read-only collection of items without duplicates.
*/
public class Gee.ReadOnlySet<G> : Object, Iterable<G>, Collection<G>, Set<G> {
+
+ /**
+ * @inheritDoc
+ */
public int size {
get { return _set.size; }
}
+ /**
+ * @inheritDoc
+ */
public bool is_empty {
get { return _set.is_empty; }
}
+ /**
+ * @inheritDoc
+ */
public new Set<G> set {
construct { _set = value; }
}
private Set<G> _set;
+ /**
+ * Read only set implementation constructor.
+ *
+ * @param set the set to decorate.
+ */
public ReadOnlySet (Set<G>? set = null) {
this.set = set;
}
+ /**
+ * @inheritDoc
+ */
public Type element_type {
get { return typeof (G); }
}
+ /**
+ * @inheritDoc
+ */
public Gee.Iterator<G> iterator () {
if (_set == null) {
return new Iterator<G> ();
return _set.iterator ();
}
+ /**
+ * @inheritDoc
+ */
public bool contains (G item) {
if (_set == null) {
return false;
return _set.contains (item);
}
+ /**
+ * Unimplemented method (read only set).
+ */
public bool add (G item) {
assert_not_reached ();
}
+ /**
+ * Unimplemented method (read only set).
+ */
public bool remove (G item) {
assert_not_reached ();
}
+ /**
+ * Unimplemented method (read only set).
+ */
public void clear () {
assert_not_reached ();
}
+ /**
+ * Unimplemented method (read only set).
+ */
public bool add_all (Collection<G> collection) {
assert_not_reached ();
}
+ /**
+ * @inheritDoc
+ */
public bool contains_all (Collection<G> collection) {
foreach (G element in collection) {
if (!contains (element)) {
return true;
}
+ /**
+ * Unimplemented method (read only set).
+ */
public bool remove_all (Collection<G> collection) {
assert_not_reached ();
}
+ /**
+ * Unimplemented method (read only set).
+ */
public bool retain_all (Collection<G> collection) {
assert_not_reached ();
}
+ /**
+ * @inheritDoc
+ */
public G[] to_array() {
return _set.to_array ();
}
get { return _size; }
}
+ /**
+ * The keys comparator function.
+ */
public CompareFunc key_compare_func { private set; get; }
+
+ /**
+ * The values equality testing function.
+ */
public EqualFunc value_equal_func { private set; get; }
private int _size = 0;
+ /**
+ * Tree map implementation constructor.
+ *
+ * @param key_compare_func an optional key comparator function.
+ * @param value_equal_func an optional values equality testing function.
+ */
public TreeMap (CompareFunc? key_compare_func = null, EqualFunc? value_equal_func = null) {
if (key_compare_func == null) {
key_compare_func = Functions.get_compare_func_for (typeof (K));
this.value_equal_func = value_equal_func;
}
+ /**
+ * @inheritDoc
+ */
public override Set<K> get_keys () {
return new KeySet<K,V> (this);
}
+ /**
+ * @inheritDoc
+ */
public override Collection<V> get_values () {
return new ValueCollection<K,V> (this);
}
return n == null || n.color == Node.Color.BLACK;
}
+ /**
+ * @inheritDoc
+ */
public override bool contains (K key) {
weak Node<K, V>? cur = root;
while (cur != null) {
return false;
}
+ /**
+ * @inheritDoc
+ */
public override V? get (K key) {
weak Node<K, V>? cur = root;
while (cur != null) {
fix_up (ref node);
}
+ /**
+ * @inheritDoc
+ */
public override void set (K key, V value) {
set_to_node (ref root, key, value, null, null);
root.color = Node.Color.BLACK;
}
}
+ /**
+ * @inheritDoc
+ */
public override bool remove (K key, out V? value = null) {
V node_value;
bool b = remove_from_node (ref root, key, out node_value);
return b;
}
+ /**
+ * @inheritDoc
+ */
public override void clear () {
root = null;
_size = 0;
get {return _size;}
}
+ /**
+ * The elements comparator function.
+ */
public CompareFunc compare_func { private set; get; }
private int _size = 0;
+ /**
+ * Tree set implementation constructor.
+ *
+ * @param compare_func an optional elements comparator function.
+ */
public TreeSet (CompareFunc? compare_func = null) {
if (compare_func == null) {
compare_func = Functions.get_compare_func_for (typeof (G));
this.compare_func = compare_func;
}
+ /**
+ * @inheritDoc
+ */
public override bool contains (G item) {
weak Node<G>? cur = root;
while (cur != null) {
}
}
+ /**
+ * @inheritDoc
+ *
+ * If the element already exists in the set it will not be added twice.
+ */
public override bool add (G item) {
bool r = add_to_node (ref root, item, null, null);
root.color = Node.Color.BLACK;
}
}
+ /**
+ * @inheritDoc
+ */
public override bool remove (G item) {
bool b = remove_from_node (ref root, item);
if (root != null) {
return b;
}
+ /**
+ * @inheritDoc
+ */
public override void clear () {
root = null;
_size = 0;
stamp++;
}
+ /**
+ * @inheritDoc
+ */
public override Gee.Iterator<G> iterator () {
return new Iterator<G> (this);
}