abstractmultiset.vala \
abstractqueue.vala \
abstractset.vala \
+ abstractsortedset.vala \
arraylist.vala \
bidiriterator.vala \
bidirmapiterator.vala \
readonlylist.vala \
readonlymap.vala \
readonlyset.vala \
+ readonlysortedset.vala \
set.vala \
sortedmap.vala \
sortedset.vala \
--- /dev/null
+/* abstractsortedset.vala
+ *
+ * Copyright (C) 2009-2011 Maciej Piechotka
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Maciej Piechotka <uzytkownik2@gmail.com>
+ */
+
+/**
+ * Skeletal implementation of the {@link SortedSet} interface.
+ *
+ * Contains common code shared by all set implementations.
+ *
+ * @see TreeSet
+ */
+public abstract class Gee.AbstractSortedSet<G> : Gee.AbstractSet<G>, SortedSet<G> {
+ /**
+ * {@inheritDoc}
+ */
+ public abstract G first ();
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract G last ();
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract BidirIterator<G> bidir_iterator ();
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract BidirIterator<G>? iterator_at (G element);
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract G? lower (G element);
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract G? higher (G element);
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract G? floor (G element);
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract G? ceil (G element);
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract SortedSet<G> head_set (G before);
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract SortedSet<G> tail_set (G after);
+
+ /**
+ * {@inheritDoc}
+ */
+ public abstract SortedSet<G> sub_set (G from, G to);
+
+ private weak SortedSet<G> _read_only_view;
+
+ /**
+ * {@inheritDoc}
+ */
+ public virtual new SortedSet<G> read_only_view {
+ owned get {
+ SortedSet<G> instance = _read_only_view;
+ if (_read_only_view == null) {
+ instance = new ReadOnlySortedSet<G> (this);
+ _read_only_view = instance;
+ instance.add_weak_pointer ((void**) (&_read_only_view));
+ }
+ return instance;
+ }
+ }
+}
+
--- /dev/null
+/* readonlysortedset.vala
+ *
+ * Copyright (C) 2009 Didier Villevalois, Maciej Piechotka
+ * Copyright (C) 2011 Maciej Piechotka
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author:
+ * Maciej Piechotka <uzytkownik2@gmail.com>
+ */
+
+/**
+ * Read-only view for {@link SortedSet} collections.
+ *
+ * This class decorates any class which implements the {@link SortedSet} interface
+ * by making it read only. Any method which normally modify data will throw an
+ * error.
+ *
+ * @see SortedSet
+ */
+internal class Gee.ReadOnlySortedSet<G> : ReadOnlySet<G>, SortedSet<G> {
+ /**
+ * Constructs a read-only set that mirrors the content of the specified set.
+ *
+ * @param set the set to decorate.
+ */
+ public ReadOnlySortedSet (SortedSet<G> set) {
+ base (set);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public G first () {
+ return (_collection as SortedSet<G>).first ();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public G last () {
+ return (_collection as SortedSet<G>).last ();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Gee.BidirIterator<G> bidir_iterator () {
+ return new BidirIterator<G> ((_collection as SortedSet<G>).bidir_iterator ());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Gee.BidirIterator<G>? iterator_at (G element) {
+ var iter = (_collection as SortedSet<G>).iterator_at (element);
+ return (iter != null) ? new BidirIterator<G> (iter) : null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public G? lower (G element) {
+ return (_collection as SortedSet<G>).lower (element);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public G? higher (G element) {
+ return (_collection as SortedSet<G>).higher (element);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public G? floor (G element) {
+ return (_collection as SortedSet<G>).floor (element);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public G? ceil (G element) {
+ return (_collection as SortedSet<G>).ceil (element);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public SortedSet<G> head_set (G before) {
+ return (_collection as SortedSet<G>).head_set (before).read_only_view;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public SortedSet<G> tail_set (G after) {
+ return(_collection as SortedSet<G>).tail_set (after).read_only_view;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public SortedSet<G> sub_set (G from, G to) {
+ return (_collection as SortedSet<G>).sub_set (from, to).read_only_view;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public new SortedSet<G> read_only_view {
+ owned get {
+ return this;
+ }
+ }
+
+ protected class BidirIterator<G> : Gee.ReadOnlyCollection.Iterator<G>, Gee.BidirIterator<G> {
+ public BidirIterator (Gee.BidirIterator<G> iterator) {
+ base (iterator);
+ }
+
+ public bool first () {
+ return (_iter as Gee.BidirIterator<G>).first ();
+ }
+
+ public bool previous () {
+ return (_iter as Gee.BidirIterator<G>).previous ();
+ }
+
+ public bool has_previous () {
+ return (_iter as Gee.BidirIterator<G>).has_previous ();
+ }
+
+ public bool last () {
+ return (_iter as Gee.BidirIterator<G>).last ();
+ }
+ }
+}
+
/* sortedset.vala
*
* Copyright (C) 2009 Didier Villevalois, Maciej Piechotka
+ * Copyright (C) 2011 Maciej Piechotka
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* @return the corresponding sub-set of this sorted set
*/
public abstract SortedSet<G> sub_set (G from, G to);
+
+ /**
+ * The read-only view of this set.
+ */
+ public abstract new SortedSet<G> read_only_view { owned get; }
+
+ /**
+ * Returns an immutable empty sorted set.
+ *
+ * @return an immutable empty sorted set
+ */
+ public static SortedSet<G> empty<G> () {
+ return new TreeSet<G> ().read_only_view;
+ }
}
public K? ceil (K item) {
return _map.lift_null_key (_map.find_ceil (item));
}
+
+ public new SortedSet<K> read_only_view {
+ owned get { return this; }
+ }
}
private class SubKeySet<K,V> : AbstractSet<K>, SortedSet<K> {
var h = map.lift_null_key (map.find_ceil (key));
return h != null && range.in_range (h) ? h : null;
}
+
+ public new SortedSet<K> read_only_view {
+ owned get { return this; }
+ }
}
private class ValueCollection<K,V> : AbstractCollection<V> {
weak Node<K,V>? l = _map.find_ceil (item.key);
return l != null ? Entry.entry_for<K,V> (l) : null;
}
+
+ public new SortedSet<Map.Entry<K, V>> read_only_view {
+ owned get { return this; }
+ }
}
private class SubEntrySet<K,V> : AbstractSet<Map.Entry<K,V>>, SortedSet<Map.Entry<K,V>> {
weak Node<K,V>? h = map.find_ceil (entry.key);
return h != null && range.in_range (h.key) ? Entry.entry_for<K,V> (h) : null;
}
+
+ public new SortedSet<Map.Entry<K, V>> read_only_view {
+ owned get { return this; }
+ }
}
private class NodeIterator<K, V> : Object {
/* treeset.vala
*
- * Copyright (C) 2009-2010 Maciej Piechotka
+ * Copyright (C) 2009-2011 Maciej Piechotka
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
*
* @see HashSet
*/
-public class Gee.TreeSet<G> : AbstractSet<G>, SortedSet<G> {
+public class Gee.TreeSet<G> : AbstractSortedSet<G> {
/**
* {@inheritDoc}
*/
/**
* {@inheritDoc}
*/
- public BidirIterator<G> bidir_iterator () {
+ public override BidirIterator<G> bidir_iterator () {
return new Iterator<G> (this);
}
/**
* {@inheritDoc}
*/
- public G first () {
+ public override G first () {
assert (_first != null);
return _first.key;
}
/**
* {@inheritDoc}
*/
- public G last () {
+ public override G last () {
assert (_last != null);
return _last.key;
}
/**
* {@inheritDoc}
*/
- public SortedSet<G> head_set (G before) {
+ public override SortedSet<G> head_set (G before) {
return new SubSet<G>.head (this, before);
}
/**
* {@inheritDoc}
*/
- public SortedSet<G> tail_set (G after) {
+ public override SortedSet<G> tail_set (G after) {
return new SubSet<G>.tail (this, after);
}
/**
* {@inheritDoc}
*/
- public SortedSet<G> sub_set (G after, G before) {
+ public override SortedSet<G> sub_set (G after, G before) {
return new SubSet<G> (this, after, before);
}
/**
* {@inheritDoc}
*/
- public BidirIterator<G>? iterator_at (G item) {
+ public override BidirIterator<G>? iterator_at (G item) {
weak Node<G>? node = find_node (item);
return node != null ? new Iterator<G>.pointing (this, node) : null;
}
/**
* {@inheritDoc}
*/
- public G? lower (G item) {
+ public override G? lower (G item) {
return lift_null_get (find_lower (item));
}
/**
* {@inheritDoc}
*/
- public G? higher (G item) {
+ public override G? higher (G item) {
return lift_null_get (find_higher (item));
}
/**
* {@inheritDoc}
*/
- public G? floor (G item) {
+ public override G? floor (G item) {
return lift_null_get (find_floor (item));
}
/**
* {@inheritDoc}
*/
- public G? ceil (G item) {
+ public override G? ceil (G item) {
return lift_null_get (find_ceil (item));
}
BOUNDED
}
- private class SubSet<G> : AbstractSet<G>, SortedSet<G> {
+ private class SubSet<G> : AbstractSortedSet<G> {
public SubSet (TreeSet<G> set, G after, G before) {
this.set = set;
this.range = new Range<G> (set, after, before);
return new SubIterator<G> (set, range);
}
- public BidirIterator<G> bidir_iterator () {
+ public override BidirIterator<G> bidir_iterator () {
return new SubIterator<G> (set, range);
}
- public G first () {
+ public override G first () {
weak Node<G>? _first = range.first ();
assert (_first != null);
return _first.key;
}
- public G last () {
+ public override G last () {
weak Node<G>? _last = range.last ();
assert (_last != null);
return _last.key;
}
- public SortedSet<G> head_set (G before) {
+ public override SortedSet<G> head_set (G before) {
return new SubSet<G>.from_range (set, range.cut_tail (before));
}
- public SortedSet<G> tail_set (G after) {
+ public override SortedSet<G> tail_set (G after) {
return new SubSet<G>.from_range (set, range.cut_head (after));
}
- public SortedSet<G> sub_set (G after, G before) {
+ public override SortedSet<G> sub_set (G after, G before) {
return new SubSet<G>.from_range (set, range.cut (after, before));
}
- public BidirIterator<G>? iterator_at (G item) {
+ public override BidirIterator<G>? iterator_at (G item) {
if (!range.in_range (item))
return null;
weak Node<G>? n = set.find_node (item);
return new SubIterator<G>.pointing (set, range, n);
}
- public G? lower (G item) {
+ public override G? lower (G item) {
var res = range.compare_range (item);
if (res > 0)
return last ();
return l != null && range.in_range (l) ? l : null;
}
- public G? higher (G item) {
+ public override G? higher (G item) {
var res = range.compare_range (item);
if (res < 0)
return first ();
return h != null && range.in_range (h) ? h : null;
}
- public G? floor (G item) {
+ public override G? floor (G item) {
var res = range.compare_range (item);
if (res > 0)
return last ();
return l != null && range.in_range (l) ? l : null;
}
- public G? ceil (G item) {
+ public override G? ceil (G item) {
var res = range.compare_range (item);
if (res < 0)
return first ();