hash_table.cc

Go to the documentation of this file.
00001 
00002 /*
00003  * hash_table.cc
00004  * Copyright (C) 2000 by the University of Southern California
00005  * $Id: hash_table.cc,v 1.5 2005/08/25 18:58:04 johnh Exp $
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License,
00009  * version 2, as published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with this program; if not, write to the Free Software Foundation, Inc.,
00018  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00019  *
00020  *
00021  * The copyright of this module includes the following
00022  * linking-with-specific-other-licenses addition:
00023  *
00024  * In addition, as a special exception, the copyright holders of
00025  * this module give you permission to combine (via static or
00026  * dynamic linking) this module with free software programs or
00027  * libraries that are released under the GNU LGPL and with code
00028  * included in the standard release of ns-2 under the Apache 2.0
00029  * license or under otherwise-compatible licenses with advertising
00030  * requirements (or modified versions of such code, with unchanged
00031  * license).  You may copy and distribute such a system following the
00032  * terms of the GNU GPL for this module and the licenses of the
00033  * other code concerned, provided that you include the source code of
00034  * that other code when and as the GNU GPL requires distribution of
00035  * source code.
00036  *
00037  * Note that people who make modified versions of this module
00038  * are not obligated to grant this special exception for their
00039  * modified versions; it is their choice whether to do so.  The GNU
00040  * General Public License gives permission to release a modified
00041  * version without this exception; this exception also makes it
00042  * possible to release a modified version which carries forward this
00043  * exception.
00044  *
00045  */
00046 
00047 
00048 // Written by Chalermek Intanagonwiwat
00049 
00050 #include "tclcl.h"
00051 #include "diff_header.h"
00052 #include "hash_table.h"
00053 #include "diff_prob.h"
00054 
00055 
00056 Pkt_Hash_Entry::~Pkt_Hash_Entry() {
00057     clear_fromagent(from_agent);
00058     if (timer != NULL)
00059       delete timer;
00060 }
00061 
00062 
00063 void Pkt_Hash_Entry::clear_fromagent(From_List *list)
00064 {
00065   From_List *cur=list;
00066   From_List *temp = NULL;
00067 
00068   while (cur != NULL) {
00069     temp = FROM_NEXT(cur);
00070     delete cur;
00071     cur = temp;
00072   }
00073 }
00074 
00075 void Pkt_Hash_Table::reset()
00076 {
00077   Pkt_Hash_Entry *hashPtr;
00078   Tcl_HashEntry *entryPtr;
00079   Tcl_HashSearch searchPtr;
00080 
00081   entryPtr = Tcl_FirstHashEntry(&htable, &searchPtr);
00082   while (entryPtr != NULL) {
00083     hashPtr = (Pkt_Hash_Entry *)Tcl_GetHashValue(entryPtr);
00084     delete hashPtr;
00085     Tcl_DeleteHashEntry(entryPtr);
00086     entryPtr = Tcl_NextHashEntry(&searchPtr);
00087   }
00088 }
00089 
00090 Pkt_Hash_Entry *Pkt_Hash_Table::GetHash(ns_addr_t sender_id, 
00091                     unsigned int pk_num)
00092 {
00093   unsigned int key[3];
00094 
00095   key[0] = sender_id.addr_;
00096   key[1] = sender_id.port_;
00097   key[2] = pk_num;
00098 
00099   Tcl_HashEntry *entryPtr = Tcl_FindHashEntry(&htable, (char *)key);
00100 
00101   if (entryPtr == NULL )
00102      return NULL;
00103 
00104   return (Pkt_Hash_Entry *)Tcl_GetHashValue(entryPtr);
00105 }
00106 
00107 
00108 void Pkt_Hash_Table::put_in_hash(hdr_cdiff *dfh)
00109 {
00110     Tcl_HashEntry *entryPtr;
00111     Pkt_Hash_Entry    *hashPtr;
00112     unsigned int key[3];
00113     int newPtr;
00114 
00115     key[0]=(dfh->sender_id).addr_;
00116     key[1]=(dfh->sender_id).port_;
00117     key[2]=dfh->pk_num;
00118 
00119     entryPtr = Tcl_CreateHashEntry(&htable, (char *)key, &newPtr);
00120     if (!newPtr)
00121       return;
00122 
00123     hashPtr = new Pkt_Hash_Entry;
00124     hashPtr->forwarder_id = dfh->forward_agent_id;
00125     hashPtr->from_agent = NULL;
00126     hashPtr->is_forwarded = false;
00127     hashPtr->num_from = 0;
00128     hashPtr->timer = NULL;
00129 
00130     Tcl_SetHashValue(entryPtr, hashPtr);
00131 }
00132 
00133 
00134 void Data_Hash_Table::reset()
00135 {
00136   Tcl_HashEntry *entryPtr;
00137   Tcl_HashSearch searchPtr;
00138 
00139   entryPtr = Tcl_FirstHashEntry(&htable, &searchPtr);
00140   while (entryPtr != NULL) {
00141     Tcl_DeleteHashEntry(entryPtr);
00142     entryPtr = Tcl_NextHashEntry(&searchPtr);
00143   }
00144 }
00145 
00146 
00147 Tcl_HashEntry *Data_Hash_Table::GetHash(int *attr)
00148 {
00149   return Tcl_FindHashEntry(&htable, (char *)attr);
00150 }
00151 
00152 
00153 void Data_Hash_Table::PutInHash(int *attr)
00154 {
00155     int newPtr;
00156 
00157     Tcl_CreateHashEntry(&htable, (char *)attr, &newPtr);
00158 }
00159 
00160 
00161 
00162 
00163 

Generated on Tue Mar 6 16:47:45 2007 for ns2 Network Simulator 2.29 by  doxygen 1.4.6