diff options
Diffstat (limited to 'src/mt/msmap.cc')
| -rw-r--r-- | src/mt/msmap.cc | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/mt/msmap.cc b/src/mt/msmap.cc new file mode 100644 index 0000000..c1284fb --- /dev/null +++ b/src/mt/msmap.cc | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | /************************************************************************* | ||
| 2 | * | ||
| 3 | * HTCd - Copyright (C) 1998-2006 Henrik Rydberg | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include <mt/msmap.h> | ||
| 21 | #include <algorithm> | ||
| 22 | using namespace std; | ||
| 23 | |||
| 24 | const sref* rrmap::get(const sref& t) const | ||
| 25 | { | ||
| 26 | pair<const_iterator,const_iterator> p=equal_range(begin(),end(),rrstring(t)); | ||
| 27 | return p.first!=p.second?&p.first->second:0; | ||
| 28 | } | ||
| 29 | |||
| 30 | const sref* rrmap::add(const sref& t,const sref& s) | ||
| 31 | { | ||
| 32 | rrstring tmp(t,s); | ||
| 33 | pair<iterator,iterator> p=equal_range(begin(),end(),tmp); | ||
| 34 | if(p.first!=p.second) return &(*p.first=tmp).second; | ||
| 35 | else return &insert(p.second,tmp)->second; | ||
| 36 | } | ||
| 37 | |||
| 38 | void rrmap::sort() | ||
| 39 | { | ||
| 40 | ::sort(begin(),end()); | ||
| 41 | } | ||
| 42 | |||
| 43 | //////////////////////////////////////////////////////////////// | ||
| 44 | |||
| 45 | int rimap::get(const sref& t) const | ||
| 46 | { | ||
| 47 | pair<const_iterator,const_iterator> p=equal_range(begin(),end(),rimap_t(t)); | ||
| 48 | return p.first!=p.second?p.first->at:-1; | ||
| 49 | } | ||
| 50 | |||
| 51 | int rimap::add(const sref& t,int at) | ||
| 52 | { | ||
| 53 | rimap_t tmp(t,at); | ||
| 54 | pair<iterator,iterator> p=equal_range(begin(),end(),tmp); | ||
| 55 | if(p.first!=p.second) return (*p.first=tmp).at; | ||
| 56 | else return insert(p.second,tmp)->at; | ||
| 57 | } | ||
| 58 | |||
| 59 | void rimap::sort() | ||
| 60 | { | ||
| 61 | ::sort(begin(),end()); | ||
| 62 | } | ||
| 63 | |||
| 64 | //////////////////////////////////////////////////////////////// | ||
| 65 | |||
| 66 | const mstring* ssmap::get(const mstring& t) const | ||
| 67 | { | ||
| 68 | pair<const_iterator,const_iterator> p=equal_range(begin(),end(),sstring(t)); | ||
| 69 | return p.first!=p.second?&p.first->second:0; | ||
| 70 | } | ||
| 71 | |||
| 72 | const mstring* ssmap::add(const mstring& t,const mstring& s) | ||
| 73 | { | ||
| 74 | sstring tmp(t,s); | ||
| 75 | pair<iterator,iterator> p=equal_range(begin(),end(),tmp); | ||
| 76 | if(p.first!=p.second) return &(*p.first=tmp).second; | ||
| 77 | else return &insert(p.second,tmp)->second; | ||
| 78 | } | ||
| 79 | |||
| 80 | void ssmap::sort() | ||
| 81 | { | ||
| 82 | ::sort(begin(),end()); | ||
| 83 | } | ||
| 84 | |||
