summaryrefslogtreecommitdiff
path: root/gee
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2010-08-11 22:23:09 +0200
committerJürg Billeter <j@bitron.ch>2010-09-09 15:54:17 +0200
commit7ef23e9eb53def8b3f65ff1152b75dc077e0164f (patch)
treea156fa81bd1b0f9029b1fba0ae35f0689724aee9 /gee
parent994935e2af012d64fe053709fccfbbf76c090a54 (diff)
downloadvala-7ef23e9eb53def8b3f65ff1152b75dc077e0164f.tar.gz
gee: Replace interfaces by abstract classes to improve performance
Diffstat (limited to 'gee')
-rw-r--r--gee/Makefile.am1
-rw-r--r--gee/arraylist.vala32
-rw-r--r--gee/collection.vala2
-rw-r--r--gee/collectionobject.vala30
-rw-r--r--gee/hashmap.vala62
-rw-r--r--gee/hashset.vala22
-rw-r--r--gee/iterable.vala2
-rw-r--r--gee/iterator.vala2
-rw-r--r--gee/list.vala2
-rw-r--r--gee/map.vala2
-rw-r--r--gee/set.vala2
11 files changed, 64 insertions, 95 deletions
diff --git a/gee/Makefile.am b/gee/Makefile.am
index 15f3e9b69..ab315657d 100644
--- a/gee/Makefile.am
+++ b/gee/Makefile.am
@@ -14,7 +14,6 @@ noinst_LTLIBRARIES = \
libgee_la_VALASOURCES = \
arraylist.vala \
collection.vala \
- collectionobject.vala \
hashmap.vala \
hashset.vala \
iterable.vala \
diff --git a/gee/arraylist.vala b/gee/arraylist.vala
index b8dd48553..5d2b392d8 100644
--- a/gee/arraylist.vala
+++ b/gee/arraylist.vala
@@ -27,8 +27,8 @@ using GLib;
/**
* Arrays of arbitrary elements which grow automatically as elements are added.
*/
-public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, List<G> {
- public int size {
+public class Vala.ArrayList<G> : List<G> {
+ public override int size {
get { return _size; }
}
@@ -47,19 +47,19 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
this.equal_func = equal_func;
}
- public Type get_element_type () {
+ public override Type get_element_type () {
return typeof (G);
}
- public Vala.Iterator<G> iterator () {
+ public override Vala.Iterator<G> iterator () {
return new Iterator<G> (this);
}
- public bool contains (G item) {
+ public override bool contains (G item) {
return (index_of (item) != -1);
}
- public int index_of (G item) {
+ public override int index_of (G item) {
for (int index = 0; index < _size; index++) {
if (_equal_func (_items[index], item)) {
return index;
@@ -68,19 +68,19 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
return -1;
}
- public G? get (int index) {
+ public override G? get (int index) {
assert (index >= 0 && index < _size);
return _items[index];
}
- public void set (int index, G item) {
+ public override void set (int index, G item) {
assert (index >= 0 && index < _size);
_items[index] = item;
}
- public bool add (G item) {
+ public override bool add (G item) {
if (_size == _items.length) {
grow_if_needed (1);
}
@@ -89,7 +89,7 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
return true;
}
- public void insert (int index, G item) {
+ public override void insert (int index, G item) {
assert (index >= 0 && index <= _size);
if (_size == _items.length) {
@@ -100,7 +100,7 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
_stamp++;
}
- public bool remove (G item) {
+ public override bool remove (G item) {
for (int index = 0; index < _size; index++) {
if (_equal_func (_items[index], item)) {
remove_at (index);
@@ -110,7 +110,7 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
return false;
}
- public void remove_at (int index) {
+ public override void remove_at (int index) {
assert (index >= 0 && index < _size);
_items[index] = null;
@@ -120,7 +120,7 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
_stamp++;
}
- public void clear () {
+ public override void clear () {
for (int index = 0; index < _size; index++) {
_items[index] = null;
}
@@ -152,7 +152,7 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
_items.resize (value);
}
- private class Iterator<G> : CollectionObject, Vala.Iterator<G> {
+ private class Iterator<G> : Vala.Iterator<G> {
public ArrayList<G> list {
set {
_list = value;
@@ -170,7 +170,7 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
this.list = list;
}
- public bool next () {
+ public override bool next () {
assert (_stamp == _list._stamp);
if (_index < _list._size) {
_index++;
@@ -178,7 +178,7 @@ public class Vala.ArrayList<G> : CollectionObject, Iterable<G>, Collection<G>, L
return (_index < _list._size);
}
- public G? get () {
+ public override G? get () {
assert (_stamp == _list._stamp);
if (_index < 0 || _index >= _list._size) {
diff --git a/gee/collection.vala b/gee/collection.vala
index 11ea97aa8..6a652fcdf 100644
--- a/gee/collection.vala
+++ b/gee/collection.vala
@@ -24,7 +24,7 @@
* Serves as the base interface for implementing collection classes. Defines
* size, iteration, and modification methods.
*/
-public interface Vala.Collection<G> : Iterable<G> {
+public abstract class Vala.Collection<G> : Iterable<G> {
/**
* The number of items in this collection.
*/
diff --git a/gee/collectionobject.vala b/gee/collectionobject.vala
deleted file mode 100644
index 5a7a624b9..000000000
--- a/gee/collectionobject.vala
+++ /dev/null
@@ -1,30 +0,0 @@
-/* collectionobject.vala
- *
- * Copyright (C) 2008 Jürg Billeter
- *
- * 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:
- * Jürg Billeter <j@bitron.ch>
- */
-
-using GLib;
-
-/**
- * Base class for all collections.
- */
-public class Vala.CollectionObject {
-}
-
diff --git a/gee/hashmap.vala b/gee/hashmap.vala
index 79bcf1c4d..5159fe3ff 100644
--- a/gee/hashmap.vala
+++ b/gee/hashmap.vala
@@ -27,8 +27,8 @@ using GLib;
/**
* Hashtable implementation of the Map interface.
*/
-public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
- public int size {
+public class Vala.HashMap<K,V> : Map<K,V> {
+ public override int size {
get { return _nnodes; }
}
@@ -66,11 +66,11 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
_nodes = new Node<K,V>[_array_size];
}
- public Set<K> get_keys () {
+ public override Set<K> get_keys () {
return new KeySet<K,V> (this);
}
- public Collection<V> get_values () {
+ public override Collection<V> get_values () {
return new ValueCollection<K,V> (this);
}
@@ -83,12 +83,12 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
return node;
}
- public bool contains (K key) {
+ public override bool contains (K key) {
Node<K,V>** node = lookup_node (key);
return (*node != null);
}
- public V? get (K key) {
+ public override V? get (K key) {
Node<K,V>* node = (*lookup_node (key));
if (node != null) {
return node->value;
@@ -97,7 +97,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
}
}
- public void set (K key, V value) {
+ public override void set (K key, V value) {
Node<K,V>** node = lookup_node (key);
if (*node != null) {
(*node)->value = value;
@@ -110,7 +110,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
_stamp++;
}
- public bool remove (K key) {
+ public override bool remove (K key) {
Node<K,V>** node = lookup_node (key);
if (*node != null) {
Node<K,V> next = (owned) (*node)->next;
@@ -129,7 +129,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
return false;
}
- public void clear () {
+ public override void clear () {
for (int i = 0; i < _array_size; i++) {
Node<K,V> node = (owned) _nodes[i];
while (node != null) {
@@ -184,7 +184,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
}
}
- private class KeySet<K,V> : CollectionObject, Iterable<K>, Collection<K>, Set<K> {
+ private class KeySet<K,V> : Set<K> {
public HashMap<K,V> map {
set { _map = value; }
}
@@ -195,36 +195,36 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
this.map = map;
}
- public Type get_element_type () {
+ public override Type get_element_type () {
return typeof (K);
}
- public Iterator<K> iterator () {
+ public override Iterator<K> iterator () {
return new KeyIterator<K,V> (_map);
}
- public int size {
+ public override int size {
get { return _map.size; }
}
- public bool add (K key) {
+ public override bool add (K key) {
assert_not_reached ();
}
- public void clear () {
+ public override void clear () {
assert_not_reached ();
}
- public bool remove (K key) {
+ public override bool remove (K key) {
assert_not_reached ();
}
- public bool contains (K key) {
+ public override bool contains (K key) {
return _map.contains (key);
}
}
- private class KeyIterator<K,V> : CollectionObject, Iterator<K> {
+ private class KeyIterator<K,V> : Iterator<K> {
public HashMap<K,V> map {
set {
_map = value;
@@ -243,7 +243,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
this.map = map;
}
- public bool next () {
+ public override bool next () {
if (_node != null) {
_node = _node.next;
}
@@ -254,14 +254,14 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
return (_node != null);
}
- public K? get () {
+ public override K? get () {
assert (_stamp == _map._stamp);
assert (_node != null);
return _node.key;
}
}
- private class ValueCollection<K,V> : CollectionObject, Iterable<V>, Collection<V> {
+ private class ValueCollection<K,V> : Collection<V> {
public HashMap<K,V> map {
set { _map = value; }
}
@@ -272,31 +272,31 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
this.map = map;
}
- public Type get_element_type () {
+ public override Type get_element_type () {
return typeof (V);
}
- public Iterator<V> iterator () {
+ public override Iterator<V> iterator () {
return new ValueIterator<K,V> (_map);
}
- public int size {
+ public override int size {
get { return _map.size; }
}
- public bool add (V value) {
+ public override bool add (V value) {
assert_not_reached ();
}
- public void clear () {
+ public override void clear () {
assert_not_reached ();
}
- public bool remove (V value) {
+ public override bool remove (V value) {
assert_not_reached ();
}
- public bool contains (V value) {
+ public override bool contains (V value) {
Iterator<V> it = iterator ();
while (it.next ()) {
if (_map._value_equal_func (it.get (), value)) {
@@ -307,7 +307,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
}
}
- private class ValueIterator<K,V> : CollectionObject, Iterator<V> {
+ private class ValueIterator<K,V> : Iterator<V> {
public HashMap<K,V> map {
set {
_map = value;
@@ -326,7 +326,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
this.map = map;
}
- public bool next () {
+ public override bool next () {
if (_node != null) {
_node = _node.next;
}
@@ -337,7 +337,7 @@ public class Vala.HashMap<K,V> : CollectionObject, Map<K,V> {
return (_node != null);
}
- public V? get () {
+ public override V? get () {
assert (_stamp == _map._stamp);
assert (_node != null);
return _node.value;
diff --git a/gee/hashset.vala b/gee/hashset.vala
index 7f188e18a..01452c669 100644
--- a/gee/hashset.vala
+++ b/gee/hashset.vala
@@ -27,8 +27,8 @@ using GLib;
/**
* Hashtable implementation of the Set interface.
*/
-public class Vala.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set<G> {
- public int size {
+public class Vala.HashSet<G> : Set<G> {
+ public override int size {
get { return _nnodes; }
}
@@ -69,20 +69,20 @@ public class Vala.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set
return node;
}
- public bool contains (G key) {
+ public override bool contains (G key) {
Node<G>** node = lookup_node (key);
return (*node != null);
}
- public Type get_element_type () {
+ public override Type get_element_type () {
return typeof (G);
}
- public Vala.Iterator<G> iterator () {
+ public override Vala.Iterator<G> iterator () {
return new Iterator<G> (this);
}
- public bool add (G key) {
+ public override bool add (G key) {
Node<G>** node = lookup_node (key);
if (*node != null) {
return false;
@@ -96,7 +96,7 @@ public class Vala.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set
}
}
- public bool remove (G key) {
+ public override bool remove (G key) {
Node<G>** node = lookup_node (key);
if (*node != null) {
Node<G> next = (owned) (*node)->next;
@@ -114,7 +114,7 @@ public class Vala.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set
return false;
}
- public void clear () {
+ public override void clear () {
for (int i = 0; i < _array_size; i++) {
Node<G> node = (owned) _nodes[i];
while (node != null) {
@@ -166,7 +166,7 @@ public class Vala.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set
}
}
- private class Iterator<G> : CollectionObject, Vala.Iterator<G> {
+ private class Iterator<G> : Vala.Iterator<G> {
public HashSet<G> set {
set {
_set = value;
@@ -185,7 +185,7 @@ public class Vala.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set
this.set = set;
}
- public bool next () {
+ public override bool next () {
if (_node != null) {
_node = _node.next;
}
@@ -196,7 +196,7 @@ public class Vala.HashSet<G> : CollectionObject, Iterable<G>, Collection<G>, Set
return (_node != null);
}
- public G? get () {
+ public override G? get () {
assert (_stamp == _set._stamp);
assert (_node != null);
return _node.key;
diff --git a/gee/iterable.vala b/gee/iterable.vala
index a95bd735d..b0097ac11 100644
--- a/gee/iterable.vala
+++ b/gee/iterable.vala
@@ -26,7 +26,7 @@ using GLib;
* Implemented by classes that support a simple iteration over instances of the
* collection.
*/
-public interface Vala.Iterable<G> : CollectionObject {
+public abstract class Vala.Iterable<G> {
public abstract Type get_element_type ();
/**
diff --git a/gee/iterator.vala b/gee/iterator.vala
index 9677e8832..5190fb652 100644
--- a/gee/iterator.vala
+++ b/gee/iterator.vala
@@ -24,7 +24,7 @@
* Implemented by classes that support a simple iteration over instances of the
* collection.
*/
-public interface Vala.Iterator<G> : CollectionObject {
+public abstract class Vala.Iterator<G> {
/**
* Advances to the next element in the iteration.
*
diff --git a/gee/list.vala b/gee/list.vala
index 3f1357628..e11399cba 100644
--- a/gee/list.vala
+++ b/gee/list.vala
@@ -23,7 +23,7 @@
/**
* Represents a collection of items in a well-defined order.
*/
-public interface Vala.List<G> : Collection<G> {
+public abstract class Vala.List<G> : Collection<G> {
/**
* Returns the item at the specified index in this list.
*
diff --git a/gee/map.vala b/gee/map.vala
index c98eeb4d2..e78f794d4 100644
--- a/gee/map.vala
+++ b/gee/map.vala
@@ -23,7 +23,7 @@
/**
* A map is a generic collection of key/value pairs.
*/
-public interface Vala.Map<K,V> : CollectionObject {
+public abstract class Vala.Map<K,V> {
/**
* The number of items in this map.
*/
diff --git a/gee/set.vala b/gee/set.vala
index 03c28da20..6449023cf 100644
--- a/gee/set.vala
+++ b/gee/set.vala
@@ -23,6 +23,6 @@
/**
* A set is a collection without duplicates.
*/
-public interface Vala.Set<G> : Collection<G> {
+public abstract class Vala.Set<G> : Collection<G> {
}