diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2011-10-08 20:30:28 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2011-10-08 20:30:28 +0200 |
| commit | 5df79c53745fde5d6c3340a2979b1429cd5892c1 (patch) | |
| tree | 1a81af141708b826e9c61e8a04019994fcca8298 /src/mt/mset.cc | |
Initial import of htcd system 1.0
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/mt/mset.cc')
| -rw-r--r-- | src/mt/mset.cc | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/mt/mset.cc b/src/mt/mset.cc new file mode 100644 index 0000000..ec5b69e --- /dev/null +++ b/src/mt/mset.cc | |||
| @@ -0,0 +1,81 @@ | |||
| 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/mset.h> | ||
| 21 | #include <algorithm> | ||
| 22 | using namespace std; | ||
| 23 | |||
| 24 | mset::mset() : rpile() {} | ||
| 25 | mset::mset(const sref& in) : rpile() { | ||
| 26 | sref first,rest=in; | ||
| 27 | while(Split(first,rest)) insert(first); | ||
| 28 | } | ||
| 29 | |||
| 30 | ///////////////////////////////////////////////////////////////////////////// | ||
| 31 | |||
| 32 | int mset::exist(const sref& t) const { | ||
| 33 | pair<const_iterator,const_iterator> p=equal_range(begin(),end(),t); | ||
| 34 | return p.first!=p.second; | ||
| 35 | } | ||
| 36 | int mset::insert(const sref& t) { | ||
| 37 | pair<iterator,iterator> p=equal_range(begin(),end(),t); | ||
| 38 | if(p.first==p.second) { rpile::insert(p.second,t); return 1; } | ||
| 39 | else return 0; | ||
| 40 | } | ||
| 41 | |||
| 42 | ///////////////////////////////////////////////////////////////////////////// | ||
| 43 | |||
| 44 | void mset::Union(const mset& a,const mset& b) { | ||
| 45 | clear(); | ||
| 46 | for(int i=0;i<a.size();i++) insert(a[i]); | ||
| 47 | for(int i=0;i<b.size();i++) insert(b[i]); | ||
| 48 | } | ||
| 49 | void mset::Intersection(const mset& a,const mset& b) { | ||
| 50 | clear(); | ||
| 51 | for(int i=0;i<a.size();i++) if(b.exist(a[i])) insert(a[i]); | ||
| 52 | } | ||
| 53 | void mset::Difference(const mset& a,const mset& b) { | ||
| 54 | clear(); | ||
| 55 | for(int i=0;i<a.size();i++) if(!b.exist(a[i])) insert(a[i]); | ||
| 56 | } | ||
| 57 | |||
| 58 | ///////////////////////////////////////////////////////////////////////////// | ||
| 59 | |||
| 60 | mstream& operator<<(mstream& out,const mset& m) { | ||
| 61 | for(int i=0;i<m.size();i++) { if(i) out.put(' '); out<<m[i]; } return out; | ||
| 62 | } | ||
| 63 | |||
| 64 | ///////////////////////////////////////////////////////////////////////////// | ||
| 65 | |||
| 66 | int msset::exist(const mstring& t) const { | ||
| 67 | pair<const_iterator,const_iterator> p=equal_range(begin(),end(),t); | ||
| 68 | return p.first!=p.second; | ||
| 69 | } | ||
| 70 | int msset::insert(const mstring& t) { | ||
| 71 | pair<iterator,iterator> p=equal_range(begin(),end(),t); | ||
| 72 | if(p.first==p.second) { spile::insert(p.second,t); return 1; } | ||
| 73 | else return 0; | ||
| 74 | } | ||
| 75 | |||
| 76 | ///////////////////////////////////////////////////////////////////////////// | ||
| 77 | |||
| 78 | mstream& operator<<(mstream& out,const msset& m) { | ||
| 79 | for(int i=0;i<m.size();i++) { if(i) out.put(' '); out<<m[i]; } return out; | ||
| 80 | } | ||
| 81 | |||
