deps/kb_meme/meme-5.0.1/src/object-list.c
/*************************************************************************
 * Store an object in a list.
 *
 * It is legal to give a NULL key; just don't try to retrieve by key later.
 *************************************************************************/
Store an object in a list.
It is legal to give a NULL key; just don't try to retrieve by key later.
Store an object in a list . It is legal to give a NULL key ; just don ' t try to retrieve by key later .
void store_object
 (void*          object,
  void*          key,       
  double         score,     
  OBJECT_LIST_T* an_object_list)
{
  if (object == NULL) {
    die("Adding null OBJECT to list.");
  }
  if (an_object_list == NULL) {
    die("Adding OBJECT to null list.");
  }
  if ((key != NULL) && (retrieve_object(key, an_object_list) != NULL)) {
    fprintf(stderr, "Adding OBJECT that was already in the list.\n");
    return;
  }
  if (an_object_list->num_objects >= an_object_list->max_objects) {
    an_object_list->max_objects += DEFAULT_MAX_OBJECTS;
    an_object_list->objects = (OBJECT_T*)mm_realloc(an_object_list->objects,
						    an_object_list->max_objects 
						    * sizeof(OBJECT_T));
  }
  if (key != NULL) {
    an_object_list->objects[an_object_list->num_objects].key
      = an_object_list->copy_key(key);
  } else {
    an_object_list->objects[an_object_list->num_objects].key = NULL;
  }
  an_object_list->objects[an_object_list->num_objects].score = score;
  an_object_list->objects[an_object_list->num_objects].value = object;
  (an_object_list->num_objects)++;
}
void store_object ( void * object , void * key , double score , OBJECT_LIST_T * an_object_list ) { if ( object == NULL ) { die ( " " ) ; } if ( an_object_list == NULL ) { die ( " " ) ; } if ( ( key != NULL ) && ( retrieve_object ( key , an_object_list ) != NULL ) ) { fprintf ( stderr , " \n " ) ; return ; } if ( an_object_list -> num_objects >= an_object_list -> max_objects ) { an_object_list -> max_objects += DEFAULT_MAX_OBJECTS ; an_object_list -> objects = ( OBJECT_T * ) mm_realloc ( an_object_list -> objects , an_object_list -> max_objects * sizeof ( OBJECT_T ) ) ; } if ( key != NULL ) { an_object_list -> objects [ an_object_list -> num_objects ] . key = an_object_list -> copy_key ( key ) ; } else { an_object_list -> objects [ an_object_list -> num_objects ] . key = NULL ; } an_object_list -> objects [ an_object_list -> num_objects ] . score = score ; an_object_list -> objects [ an_object_list -> num_objects ] . value = object ; ( an_object_list -> num_objects ) ++ ; }
Store an object in a list.
Store an object in a list .
// Key for use in retrieval. // Score for use in sorting. // Make sure none of the inputs is null. // If it's already there, don't do anything. // Reallocate space if there isn't any. // Add to the list.