libStatGen Software
1
|
00001 /* 00002 * Copyright (C) 2010 Regents of the University of Michigan 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #include "LongLongCounter.h" 00019 00020 LongCounter::LongCounter() : LongHash<int>() 00021 { 00022 SetAllowDuplicateKeys(false); 00023 } 00024 00025 void LongCounter::IncrementCount(long long key) 00026 { 00027 unsigned int slot = Find(key); 00028 00029 if (slot == LH_NOTFOUND) 00030 Add(key, 1); 00031 else if (Object(slot) == -1) 00032 Delete(slot); 00033 else 00034 Object(slot)++; 00035 } 00036 00037 void LongCounter::DecrementCount(long long key) 00038 { 00039 unsigned int slot = Find(key); 00040 00041 if (slot == LH_NOTFOUND) 00042 Add(key, -1); 00043 else if (Object(slot) == 1) 00044 Delete(slot); 00045 else 00046 Object(slot)--; 00047 } 00048 00049 int LongCounter::GetCount(long long key) 00050 { 00051 unsigned int slot = Find(key); 00052 00053 if (slot == LH_NOTFOUND) 00054 return 0; 00055 else 00056 return Object(slot)--; 00057 } 00058 00059