Exemplo n.º 1
0
//Public interfaces for Finding a Node by its value from the HashTable
//On SUCCESS returns the Node; NULL otherwise
Node* HashTable::Find(const string& aValue) const
{
    Node*  pNode = NULL;
    size_t hashIndex = 0;

    hashIndex = HashIndex(aValue);
    pNode = iTable[hashIndex].Find(aValue);

    return pNode;
}
static int
InsertHash(Socket sd) {
  int i;
  IPAddress temp_addr;
  if(!HashIndex(sd, &i, &temp_addr)) {
    FAIL("InsertHash: can't insert addr (failed getpeername)\n");
  }
  Addrs[i] = temp_addr;
  Pkt_to[i].timeout = PKTTIMEOUT;
  return(1);
}
/*
========================
idLZWCompressor::AddToDict 
========================
*/
int idLZWCompressor::AddToDict( int w, int k ) {
	assert( w < 0xFFFF - 1 );
	assert( k < 256 );
	assert( lzwData->nextCode < lzwCompressionData_t::LZW_DICT_SIZE );
	
	lzwData->dictionaryK[lzwData->nextCode] = (uint8)k;
	lzwData->dictionaryW[lzwData->nextCode] = (uint16)w;
	int i = HashIndex( w, k );
	nextHash[lzwData->nextCode] = hash[i];
	hash[i] = (uint16)lzwData->nextCode;
	return lzwData->nextCode++;
}
Exemplo n.º 4
0
Node* HashTable::Find(const char* pValue) const
{
    Node*  pNode = NULL;
    size_t hashIndex = 0;
    string val(pValue);

    if (pValue) {
        hashIndex = HashIndex(val);
        pNode = iTable[hashIndex].Find(val);
    }

    return pNode;
}
Exemplo n.º 5
0
//Public interfaces for Removing a Node by its value from the HashTable
//On SUCCESS returns true; false otherwise
bool HashTable::Remove(const string& aValue)
{
    bool   bSuccess = false;
    size_t hashIndex = 0;

    hashIndex = HashIndex(aValue);
    bSuccess = iTable[hashIndex].Remove(aValue);
    if (bSuccess) {
        iLength--;
    }

    return bSuccess;
}
Exemplo n.º 6
0
bool HashTable::Insert(const string& aValue)
{
    bool   bSuccess = false;
    size_t hashIndex = 0;

    hashIndex = HashIndex(aValue);
    bSuccess = iTable[hashIndex].Insert(aValue);
    if (bSuccess) {
        iLength++;
    }

    return bSuccess;
}
Exemplo n.º 7
0
//Public interfaces for Inserting a Node to the HashTable
//On SUCCESS returns true; false otherwise
bool HashTable::Insert(Node* pNode, bool bOwnIt)
{
    bool   bSuccess = false;
    size_t hashIndex = 0;

    if (pNode) {
        hashIndex = HashIndex(pNode->Value());
        bSuccess = iTable[hashIndex].Insert(pNode, bOwnIt);
        if (bSuccess) {
            iLength++;
        }
    }

    return bSuccess;
}
double
PktTimeOut(Socket sd) {
  int hashindex;
  IPAddress temp_addr;
  double time_out;

  /* XXX check to see if this peer is indexed already */
  time_out = HashIndex(sd, &hashindex, &temp_addr) ?
         Pkt_to[hashindex].timeout : PKTTIMEOUT;

  if(time_out == 0)
	time_out = PKTTIMEOUT;

  return(time_out);
}
/*
========================
idLZWCompressor::Lookup 
========================
*/
int idLZWCompressor::Lookup( int w, int k ) {
	if ( w == -1 ) {
		return k;
	} else {
		int i = HashIndex( w, k );
		
		for ( int j = hash[i]; j != 0xFFFF; j = nextHash[j] ) {
			assert( j < lzwCompressionData_t::LZW_DICT_SIZE );
			if ( lzwData->dictionaryK[j] == k && lzwData->dictionaryW[j] == w ) { 
				return j;
			}
		}
	}
	return -1;
}
void
SetPktTimeOut(Socket sd,
              double duration,
              int timedOut) {

  IPAddress addr;
  double dev;
  double err;
  double est;
  int hashindex;
  double timeout;

  if(HashIndex(sd,&hashindex, &addr) == 0) {
    WARN("SetPktTimeOut: HashIndex failed (getpeername)\n");
    return;
  }

  est = Pkt_to[hashindex].est;
  dev = Pkt_to[hashindex].dev;
  err = est - duration;

  if(err < 0.0)
    err = err * -1.0;

  est = est + PGAIN * (duration - est);

  if(timedOut)
    est++;

  dev = dev + PGAIN * (err - dev);

  if(dev < 0.0)
    dev = -1.0 * dev;

  timeout = est + 2 * dev;

  Pkt_to[hashindex].est = est;
  Pkt_to[hashindex].dev = dev;

  if(timeout < MINPKTTIMEOUT)
    timeout = MINPKTTIMEOUT;

  if(timeout > MAXPKTTIMEOUT)
    timeout = MAXPKTTIMEOUT;

  Pkt_to[hashindex].timeout = timeout;

}
Exemplo n.º 11
0
bool HashTable::Remove(const char* pValue)
{
    bool   bSuccess = false;
    size_t hashIndex = 0;
    string val(pValue);

    if (pValue) {
        hashIndex = HashIndex(val);
        bSuccess = iTable[hashIndex].Remove(val);
        if (bSuccess) {
            iLength--;
        }
    }

    return bSuccess;
}