/* UpTools v8.6 * * Copyright (c) 2005-2013 Fundacion Universidad de Palermo (Argentina). * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: 'This product includes software developed by the * "Universidad de Palermo, Argentina" (http://www.palermo.edu/).' * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <UpTools/UpHashMap.h> #include <UpTools/UpInet.h> #include <iostream> #include <string> using namespace std; typedef UPHASH_MAP<UpSockAddr,string,UpHash,UpEq> UpSockAddrHashMap; typedef std::map<UpSockAddr,string,UpLessThan> UpSockAddrMap; int main() { UpSockAddr a4("200.6.5.4 2000"), b4("200.6.5.4 3000"),c4("200.1.1.1 12"),d4("200.1.1.1 200"); UpSockAddr a6("23fc::8989 2000"), b6("23fc::8989 3000"),c6("1111::1212 12"),d6("1111::1212 200"); UpSockAddr au("/tmp/aa1"), bu("/tmp/aa2"),cu("/tmp/bcd"),du("/var/run/socket/mysock"); UpSockAddrMap sam; UpSockAddrHashMap sahm; sam[a4]="a4"; sahm[a4]="a4"; sam[a6]="a6"; sahm[a6]="a6"; sam[au]="au"; sahm[au]="au"; sam[b4]="b4"; sahm[b4]="b4"; sam[b6]="b6"; sahm[b6]="b6"; sam[bu]="bu"; sahm[bu]="bu"; sam[c4]="c4"; sahm[c4]="c4"; sam[c6]="c6"; sahm[c6]="c6"; sam[cu]="cu"; sahm[cu]="cu"; sam[d4]="d4"; sahm[d4]="d4"; sam[d6]="d6"; sahm[d6]="d6"; sam[du]="du"; sahm[du]="du"; UpSockAddrMap::iterator it; cout<<"sam damp - sahm lookup: "<<endl; for(it=sam.begin(); it!=sam.end(); it++) { cout <<"sam::it->first="<<it->first<<" sam::it->second="<<it->second<<"\n" <<" sahm["<<it->first<<"]= "<<sahm[it->first]<<endl; } cout<<endl; UpSockAddrHashMap::iterator iht; cout<<"sahm damp - sahm lookup: "<<endl; for(iht=sahm.begin(); iht!=sahm.end(); iht++) { cout <<"sahm::iht->first="<<iht->first<<" sam::iht->second="<<iht->second <<" keyhash="<<iht->first.hash()<<"\n" <<" sam["<<iht->first<<"]= "<<sam[iht->first]<<endl; } cout<<endl; return 0; }