summaryrefslogtreecommitdiff
path: root/gee/sortedset.vala
blob: 3e7437627e6d370d5f72fd45cb0bc95bc9e2850a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* 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
 * 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>
 */

/**
 * A sorted set, which you can navigate over and get sub-sets of.
 */
[GenericAccessors]
public interface Gee.SortedSet<G> : Gee.Set<G> {
	/**
	 * Returns the first element of the sorted set. Set must not be empty.
	 *
	 * @return the first element in the sorted set
	 */
	public abstract G first ();

	/**
	 * Returns the last element of the sorted set. Set must not be empty.
	 *
	 * @return the last element in the sorted set
	 */
	public abstract G last ();

	/**
	 * Returns a {@link BidirIterator} initially pointed at the specified
	 * element.
	 *
	 * @param element the element to point the iterator at
	 *
	 * @return        a {@link BidirIterator} over this sorted set, or null if
	 *                the specified element is not in this set
	 */
	public abstract Iterator<G>? iterator_at (G element);

	/**
	 * Returns the element which is strictly lower than the specified element.
	 *
	 * @param element the element which you want the lower element for
	 *
	 * @return        the corresponding element
	 */
	public abstract G? lower (G element);

	/**
	 * Returns the element which is strictly higher than the specified element.
	 *
	 * @param element the element which you want the strictly higher element
	 *                for
	 *
	 * @return        the corresponding element
	 */
	public abstract G? higher (G element);

	/**
	 * Returns the element which is lower or equal then the specified element.
	 *
	 * @param element the element which you want the lower or equal element for
	 *
	 * @return        the corresponding element
	 */
	public abstract G? floor (G element);

	/**
	 * Returns the element which is higher or equal then the specified element.
	 *
	 * @param element the element which you want the higher or equal element
	 *                for
	 *
	 * @return        the corresponding element
	 */
	public abstract G? ceil (G element);

	/**
	 * Returns the sub-set of this sorted set containing elements strictly
	 * lower than the specified element.
	 *
	 * @param before the lower inclusive bound for the sub-set
	 *
	 * @return     the corresponding sub-set of this sorted set
	 */
	public abstract SortedSet<G> head_set (G before);

	/**
	 * Returns the sub-set of this sorted set containing elements equal or
	 * higher than the specified element.
	 *
	 * @param after the higher exclusive bound for the sub-set
	 *
	 * @return   the corresponding sub-set of this sorted set
	 */
	public abstract SortedSet<G> tail_set (G after);

	/**
	 * Returns the right-open sub-set of this sorted set, thus containing
	 * elements equal or higher than the specified ``from`` element, and stricly
	 * lower than the specified ``to`` element.
	 *
	 * @param from the lower inclusive bound for the sub-set
	 * @param to   the higher exclusive bound for the sub-set
	 *
	 * @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;
	}
}