1 : // -*- mode: c++; tab-width: 4; indent-tabs-mode: t -*-
2 :
3 : /** @file
4 : * @author Enrico Zini <enrico@enricozini.org>
5 : * Quick map from package IDs to package names
6 : */
7 :
8 : /*
9 : * Copyright (C) 2007 Enrico Zini <enrico@debian.org>
10 : *
11 : * This program is free software; you can redistribute it and/or modify
12 : * it under the terms of the GNU General Public License as published by
13 : * the Free Software Foundation; either version 2 of the License, or
14 : * (at your option) any later version.
15 : *
16 : * This program is distributed in the hope that it will be useful,
17 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : * GNU General Public License for more details.
20 : *
21 : * You should have received a copy of the GNU General Public License
22 : * along with this program; if not, write to the Free Software
23 : * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 : */
25 :
26 : #include <ept/popcon/popcon.h>
27 : #include <ept/popcon/maint/popconindexer.h>
28 : #include <ept/popcon/maint/path.h>
29 :
30 : //#include <iostream>
31 :
32 : using namespace std;
33 :
34 : namespace ept {
35 : namespace popcon {
36 :
37 3 : size_t Popcon::GeneralInfo::submissions() const
38 : {
39 3 : if (!m_buf) return 0;
40 2 : return ((InfoStruct*)m_buf)->submissions;
41 : }
42 :
43 7 : Popcon::Popcon()
44 : {
45 7 : std::string scofname, idxfname;
46 :
47 7 : if (!PopconIndexer::obtainWorkingPopcon(scofname, idxfname))
48 : {
49 1 : m_timestamp = 0;
50 1 : return;
51 : }
52 :
53 : //cerr << "GOT " << scofname << " " << idxfname << endl;
54 :
55 6 : m_timestamp = Path::timestamp(idxfname);
56 :
57 6 : mastermmap.init(idxfname);
58 6 : tagcoll::diskindex::MMap::init(mastermmap, 0);
59 :
60 6 : m_info.init(mastermmap, 1);
61 :
62 : //cerr << "SIZE " << size() << endl;
63 : //for (size_t i = 0; i < size(); ++i)
64 : //{
65 : // cerr << "EL " << i << ": " << ((Score*)m_buf)[i].offset << " " << ((Score*)m_buf)[i].score << endl;
66 : //}
67 0 : }
68 :
69 1792 : float Popcon::scoreByName(const std::string& name) const
70 : {
71 : // Binary search the index to find the package ID
72 : int begin, end;
73 :
74 : /* Binary search */
75 1792 : begin = -1, end = size();
76 32470 : while (end - begin > 1)
77 : {
78 28886 : int cur = (end + begin) / 2;
79 28886 : if (this->name(cur) > name)
80 14367 : end = cur;
81 : else
82 14519 : begin = cur;
83 : }
84 :
85 1792 : if (begin == -1 || this->name(begin) != name)
86 : //throw NotFoundException(string("looking for the ID of string ") + str);
87 31 : return 0;
88 : else
89 1761 : return score(begin);
90 : }
91 :
92 : }
93 : }
94 :
95 : // vim:set ts=4 sw=4:
|