Exemplo n.º 1
0
int   project_addObject(int type, char *id, int n)
//
//  Input:   type = object type
//           id   = object ID string
//           n    = object index
//  Output:  returns 0 if object already added, 1 if not, -1 if hashing fails
//  Purpose: adds an object ID to a hash table
//
{
    int  result;
    int  len;
    char *newID;

    // --- do nothing if object already placed in hash table
    if ( project_findObject(type, id) >= 0 ) return 0;

    // --- use memory from the hash tables' common memory pool to store
    //     a copy of the object's ID string
    len = strlen(id) + 1;
    newID = (char *) Alloc(len*sizeof(char));
    strcpy(newID, id);

    // --- insert object's ID into the hash table for that type of object
    result = HTinsert(Htable[type], newID, n);
    if ( result == 0 ) result = -1;
    return result;
}
Exemplo n.º 2
0
int CSreadIndex(CompressedStream *cs, ATerm *term){
   long index;
   if(HFdecodeIndex(cs->bs, &cs->tree, &index)){
      uncalcDelta(cs,&index);
      *term=(ATerm)ATmakeInt(index); 
         HTinsert(cs->indices,*term,NULL); /* IZAK */
      return 1;
   } else {
      return 0;
   }
}
Exemplo n.º 3
0
int   addlinkID(int n, char *id)
/*
**-------------------------------------------------------------
**  Input:   n = link index
**           id = ID label
**  Output:  returns 0 if ID already in use, 1 if not
**  Purpose: adds a link ID to the Link Hash Table
**--------------------------------------------------------------
*/
{
    if (findlink(id)) return(0);         /* see EPANET.C */
    strncpy(Link[n].ID, id, MAXID);
    HTinsert(Lht, Link[n].ID, n);        /* see HASH.C */
    return(1);
}
Exemplo n.º 4
0
int   addnodeID(int n, char *id)
/*
**-------------------------------------------------------------
**  Input:   n = node index
**           id = ID label
**  Output:  returns 0 if ID already in use, 1 if not
**  Purpose: adds a node ID to the Node Hash Table
**--------------------------------------------------------------
*/
{
    if (findnode(id)) return(0);         /* see EPANET.C */
    strncpy(Node[n].ID, id, MAXID);
    HTinsert(Nht, Node[n].ID, n);        /* see HASH.C */
    return(1);
}
Exemplo n.º 5
0
int CSwriteIndex(CompressedStream *cs, ATerm term){
   long index;


   if(term==NULL){
      return HFencodeIndex(cs->bs, &cs->tree, NO_INT); 
   } else {
      if(!HTmember(cs->indices,term,&index)){
         index=HTinsert(cs->indices,term,NULL);
      }
      calcDelta(cs, &index);

      return HFencodeIndex(cs->bs, &cs->tree, index); 
   }
}
Exemplo n.º 6
0
static struct HFnode *HFadd(HFtree *tree, ATerm term){
   struct HFnode *newNode, *tmp;
   long index;


   /* Find the node with the escape sequence */
   tmp=tree->top;

   /* This is the only child of its parent? */
   if(tmp->parent->high==NULL){

      /* Create a new sibling */

      newNode=(struct HFnode*)malloc(sizeof(struct HFnode));
      newNode->high=NULL;
      newNode->low=NULL;
      newNode->parent=tmp->parent;
      newNode->frequency=0L;
      newNode->term=term;
      tmp->parent->high=newNode;

      BLinsert(&tree->blockList, newNode);

      if(HTmember(tree->terms, term, &index)){
         HTsetPtr(tree->terms,index, newNode);
      } else {
         HTinsert(tree->terms, term, newNode);
      }

      return newNode;

  } else {

      /* Create new interior node */

      newNode=(struct HFnode*)malloc(sizeof(struct HFnode));
      newNode->parent=tmp->parent;
      newNode->frequency=tmp->frequency;
      newNode->term=NULL;
      if (tmp->parent->low==tmp){
         tmp->parent->low=newNode;
      } else {
         tmp->parent->high=newNode;
      }

      /* Old leaf becomes low child of new node */

      newNode->low=tmp;
      tmp->parent=newNode;

      /* Create new leaf that is high child of new interior node */

      newNode->high=(struct HFnode*)malloc(sizeof(struct HFnode));
      newNode->high->high=NULL;
      newNode->high->low=NULL;
      newNode->high->parent=newNode;
      newNode->high->frequency=0L;
      newNode->high->term=term;

      BLinsert(&tree->blockList, newNode);
      BLinsert(&tree->blockList, newNode->high);
/*
      HTinsert(tree->terms, term, newNode->high);
*/
if(HTmember(tree->terms, term, &index)){
      HTsetPtr(tree->terms,index, newNode->high);
} else {
      HTinsert(tree->terms, term, newNode->high);
}
      return newNode->high;


   }

}