Commit 2dee3459 authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

Add List.slice method, patch by Zeeshan Ali Khattak, fixes bug 569188

2009-01-27  Jürg Billeter  <j@bitron.ch>

	* gee/arraylist.vala:
	* gee/list.vala:
	* gee/readonlylist.vala:

	Add List.slice method, patch by Zeeshan Ali Khattak,
	fixes bug 569188

svn path=/trunk/; revision=40
parent 5895a030
2009-01-27 Jürg Billeter <j@bitron.ch>
* gee/arraylist.vala:
* gee/list.vala:
* gee/readonlylist.vala:
Add List.slice method, patch by Zeeshan Ali Khattak,
fixes bug 569188
2008-11-01 Jürg Billeter <j@bitron.ch>
* configure.ac: Post-release version bump
......
......@@ -128,6 +128,19 @@ public class Gee.ArrayList<G> : Object, Iterable<G>, Collection<G>, List<G> {
_stamp++;
}
public List<G>? slice (int start, int stop) {
return_val_if_fail (start <= stop, null);
return_val_if_fail (start >= 0, null);
return_val_if_fail (stop <= this.size, null);
var slice = new ArrayList<G> (this._equal_func);
for (int i = start; i < stop; i++) {
slice.add (this[i]);
}
return slice;
}
private void shift (int start, int delta) {
assert (start >= 0 && start <= _size && start >= -delta);
......
......@@ -63,5 +63,15 @@ public interface Gee.List<G> : Collection<G> {
* @param index zero-based index of the item to be removed
*/
public abstract void remove_at (int index);
/**
* Returns a slice of this list.
*
* @param start zero-based index of the begin of the slice
* @param stop zero-based index after the end of the slice
*
* @return A list containing a slice of this list
*/
public abstract List<G>? slice (int start, int stop);
}
......@@ -100,6 +100,10 @@ public class Gee.ReadOnlyList<G> : Object, Iterable<G>, Collection<G>, List<G> {
assert_not_reached ();
}
public List<G>? slice (int start, int stop) {
assert_not_reached ();
}
class Iterator<G> : Object, Gee.Iterator<G> {
public bool next () {
return false;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment