00001 // Copyright (C) 2005, Vesta free software project 00002 // 00003 // This file is part of Vesta. 00004 // 00005 // Vesta is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // Vesta is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with Vesta; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 // ShortIdRefCount.C 00020 00021 #include "ShortIdRefCount.H" 00022 #include "logging.H" 00023 00024 bool ShortIdRefCount::Compare(const ShortIdRefCount &other) 00025 { 00026 // Make a copy of the other table. We'll remove entries from them 00027 // as we process them. 00028 ShortIdRefCount work(other); 00029 00030 // Do the counts match? 00031 bool match = true; 00032 00033 // Temp vars used while iterating over the two tables 00034 ShortIdKey sidkey; 00035 int count, ocount; 00036 00037 // First pass: iterate over this . 00038 { 00039 ShortIdRefCount::Iterator self_it(this); 00040 while(self_it.Next(sidkey, count)) 00041 { 00042 ocount = work.GetCount(sidkey.sid); 00043 if(count != ocount) 00044 { 00045 match = false; 00046 Repos::dprintf(DBG_ALWAYS, 00047 "shortid refcount mismatch on 0x%08x: %d vs. %d\n", 00048 sidkey.sid, count, ocount); 00049 } 00050 00051 // We're done with this shortid, so remove it 00052 (void) work.Delete(sidkey, count, false); 00053 } 00054 } 00055 00056 // Second pass: itetrate over anything left in the other table 00057 { 00058 ShortIdRefCount::Iterator work_it(&work); 00059 while(work_it.Next(sidkey, ocount)) 00060 { 00061 count = this->GetCount(sidkey.sid); 00062 // Since we've already processed every entry in this table, 00063 // this must be a shortid not present in this table, and thus 00064 // must have a count of zero. 00065 assert(count == 0); 00066 if(count != ocount) 00067 { 00068 match = false; 00069 Repos::dprintf(DBG_ALWAYS, 00070 "shortid refcount mismatch on 0x%08x: %d vs. %d\n", 00071 sidkey.sid, count, ocount); 00072 } 00073 } 00074 } 00075 00076 // Indicate to the caller that we have a match. 00077 return match; 00078 }