Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

hash_table.cc

Go to the documentation of this file.
00001 // Copyright (c) 2000 by the University of Southern California
00002 // All rights reserved.
00003 //
00004 // Permission to use, copy, modify, and distribute this software and its
00005 // documentation in source and binary forms for non-commercial purposes
00006 // and without fee is hereby granted, provided that the above copyright
00007 // notice appear in all copies and that both the copyright notice and
00008 // this permission notice appear in supporting documentation. and that
00009 // any documentation, advertising materials, and other materials related
00010 // to such distribution and use acknowledge that the software was
00011 // developed by the University of Southern California, Information
00012 // Sciences Institute.  The name of the University may not be used to
00013 // endorse or promote products derived from this software without
00014 // specific prior written permission.
00015 //
00016 // THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about
00017 // the suitability of this software for any purpose.  THIS SOFTWARE IS
00018 // PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
00019 // INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00020 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 //
00022 // Other copyrights might apply to parts of this software and are so
00023 // noted when applicable.
00024 //
00025 
00026 
00027 // Written by Chalermek Intanagonwiwat
00028 
00029 #include "tclcl.h"
00030 #include "diff_header.h"
00031 #include "hash_table.h"
00032 #include "diff_prob.h"
00033 
00034 
00035 Pkt_Hash_Entry::~Pkt_Hash_Entry() {
00036     clear_fromagent(from_agent);
00037     if (timer != NULL)
00038       delete timer;
00039 }
00040 
00041 
00042 void Pkt_Hash_Entry::clear_fromagent(From_List *list)
00043 {
00044   From_List *cur=list;
00045   From_List *temp = NULL;
00046 
00047   while (cur != NULL) {
00048     temp = FROM_NEXT(cur);
00049     delete cur;
00050     cur = temp;
00051   }
00052 }
00053 
00054 void Pkt_Hash_Table::reset()
00055 {
00056   Pkt_Hash_Entry *hashPtr;
00057   Tcl_HashEntry *entryPtr;
00058   Tcl_HashSearch searchPtr;
00059 
00060   entryPtr = Tcl_FirstHashEntry(&htable, &searchPtr);
00061   while (entryPtr != NULL) {
00062     hashPtr = (Pkt_Hash_Entry *)Tcl_GetHashValue(entryPtr);
00063     delete hashPtr;
00064     Tcl_DeleteHashEntry(entryPtr);
00065     entryPtr = Tcl_NextHashEntry(&searchPtr);
00066   }
00067 }
00068 
00069 Pkt_Hash_Entry *Pkt_Hash_Table::GetHash(ns_addr_t sender_id, 
00070                                         unsigned int pk_num)
00071 {
00072   unsigned int key[3];
00073 
00074   key[0] = sender_id.addr_;
00075   key[1] = sender_id.port_;
00076   key[2] = pk_num;
00077 
00078   Tcl_HashEntry *entryPtr = Tcl_FindHashEntry(&htable, (char *)key);
00079 
00080   if (entryPtr == NULL )
00081      return NULL;
00082 
00083   return (Pkt_Hash_Entry *)Tcl_GetHashValue(entryPtr);
00084 }
00085 
00086 
00087 void Pkt_Hash_Table::put_in_hash(hdr_cdiff *dfh)
00088 {
00089     Tcl_HashEntry *entryPtr;
00090     Pkt_Hash_Entry    *hashPtr;
00091     unsigned int key[3];
00092     int newPtr;
00093 
00094     key[0]=(dfh->sender_id).addr_;
00095     key[1]=(dfh->sender_id).port_;
00096     key[2]=dfh->pk_num;
00097 
00098     entryPtr = Tcl_CreateHashEntry(&htable, (char *)key, &newPtr);
00099     if (!newPtr)
00100       return;
00101 
00102     hashPtr = new Pkt_Hash_Entry;
00103     hashPtr->forwarder_id = dfh->forward_agent_id;
00104     hashPtr->from_agent = NULL;
00105     hashPtr->is_forwarded = false;
00106     hashPtr->num_from = 0;
00107     hashPtr->timer = NULL;
00108 
00109     Tcl_SetHashValue(entryPtr, hashPtr);
00110 }
00111 
00112 
00113 void Data_Hash_Table::reset()
00114 {
00115   Tcl_HashEntry *entryPtr;
00116   Tcl_HashSearch searchPtr;
00117 
00118   entryPtr = Tcl_FirstHashEntry(&htable, &searchPtr);
00119   while (entryPtr != NULL) {
00120     Tcl_DeleteHashEntry(entryPtr);
00121     entryPtr = Tcl_NextHashEntry(&searchPtr);
00122   }
00123 }
00124 
00125 
00126 Tcl_HashEntry *Data_Hash_Table::GetHash(int *attr)
00127 {
00128   return Tcl_FindHashEntry(&htable, (char *)attr);
00129 }
00130 
00131 
00132 void Data_Hash_Table::PutInHash(int *attr)
00133 {
00134     int newPtr;
00135 
00136     Tcl_CreateHashEntry(&htable, (char *)attr, &newPtr);
00137 }
00138 
00139 
00140 
00141 
00142 

Generated on Tue Apr 20 12:14:19 2004 for NS2.26SourcesOriginal by doxygen 1.3.3