2
* Copyright (C) 2010 Michal Hruby <michal.mhr@gmail.com>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Authored by Michal Hruby <michal.mhr@gmail.com>
23
public class ResultSet : Object, Gee.Traversable<Match>, Gee.Iterable <Gee.Map.Entry <Match, int>>
25
protected Gee.Map<Match, int> matches;
26
protected Gee.Set<unowned string> uris;
35
matches = new Gee.HashMap<Match, int> ();
36
// Match.uri is not owned, so we can optimize here
37
uris = new Gee.HashSet<unowned string> ();
40
public Type element_type
42
get { return matches.element_type; }
47
get { return matches.size; }
50
public Gee.Set<Match> keys
52
owned get { return matches.keys; }
55
public Gee.Set<Gee.Map.Entry <Match, int>> entries
57
owned get { return matches.entries; }
60
public Gee.Iterator<Gee.Map.Entry <Match, int>?> iterator ()
62
return matches.iterator ();
65
public bool foreach (Gee.ForallFunc<Match> func)
67
return matches.keys.foreach (func);
70
public void add (Match match, int relevancy)
72
matches.set (match, relevancy);
74
if (match is UriMatch)
76
unowned string uri = (match as UriMatch).uri;
77
if (uri != null && uri != "")
84
public void add_all (ResultSet? rs)
86
if (rs == null) return;
87
matches.set_all (rs.matches);
88
uris.add_all (rs.uris);
91
public bool contains_uri (string uri)
96
public Gee.List<Match> get_sorted_list ()
98
var l = new Gee.ArrayList<Gee.Map.Entry<Match, int>> ();
99
l.add_all (matches.entries);
103
unowned Gee.Map.Entry<Match, int> e1 = (Gee.Map.Entry<Match, int>) a;
104
unowned Gee.Map.Entry<Match, int> e2 = (Gee.Map.Entry<Match, int>) b;
105
int relevancy_delta = e2.value - e1.value;
106
if (relevancy_delta != 0) return relevancy_delta;
107
// FIXME: utf8 compare!
108
else return e1.key.title.ascii_casecmp (e2.key.title);
111
var sorted_list = new Gee.ArrayList<Match> ();
112
foreach (Gee.Map.Entry<Match, int> m in l)
114
sorted_list.add (m.key);