LTP GCOV extension - code coverage report
Current view: directory - ept/debtags/maint - pkgid.cc
Test: lcov.info
Date: 2008-08-14 Instrumented lines: 15
Code covered: 86.7 % Executed lines: 13

       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) 2003-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/debtags/maint/pkgid.h>
      27                 : #include <ept/debtags/maint/path.h>
      28                 : 
      29                 : namespace ept {
      30                 : namespace debtags {
      31                 : 
      32              10 : PkgId::PkgId() {}
      33                 : 
      34               1 : PkgId::PkgId(const char* buf, int size)
      35               1 :         : MMap(buf, size) {}
      36                 : 
      37               0 : PkgId::PkgId(const tagcoll::diskindex::MasterMMap& master, size_t idx)
      38               0 :         : MMap(master, idx) {}
      39                 : 
      40           63445 : int PkgId::byName(const std::string& name) const
      41                 : {
      42                 :         // Binary search the index to find the package ID
      43                 :         int begin, end;
      44                 : 
      45                 :         /* Binary search */
      46           63445 :         begin = -1, end = size();
      47         1043664 :         while (end - begin > 1)
      48                 :         {
      49          916774 :                 int cur = (end + begin) / 2;
      50          916774 :                 if (byID(cur) > name)
      51          443057 :                         end = cur;
      52                 :                 else
      53          473717 :                         begin = cur;
      54                 :         }
      55                 : 
      56           63445 :         if (begin == -1 || byID(begin) != name)
      57                 :                 //throw NotFoundException(string("looking for the ID of string ") + str);
      58               2 :                 return -1;
      59                 :         else
      60           63443 :                 return begin;
      61                 : }
      62                 : 
      63                 : }
      64                 : }
      65                 : 
      66                 : // vim:set ts=4 sw=4:

Generated by: LTP GCOV extension version 1.6