Esempio n. 1
0
struct string_list_item *string_list_lookup(struct string_list *list, const char *string)
{
	int exact_match, i = get_entry_index(list, string, &exact_match);
	if (!exact_match)
		return NULL;
	return list->items + i;
}
Esempio n. 2
0
int string_list_find_insert_index(const struct string_list *list, const char *string,
				  int negative_existing_index)
{
	int exact_match;
	int index = get_entry_index(list, string, &exact_match);
	if (exact_match)
		index = -1 - (negative_existing_index ? index : 0);
	return index;
}
Esempio n. 3
0
void Entries_der<T>::set_values( const int bucket,
				 const int64_t soln_idx,
				 const int num_choices,
				 const T *values )
{
  size_t base_index = get_entry_index( bucket, soln_idx );

  /* Copy the values over */
  memcpy( &entries[ base_index ], values, num_choices * sizeof( T ) );
}
Esempio n. 4
0
int Entries_der<T>::increment_entry( const int bucket, const int64_t soln_idx, const int choice )
{
  /* Get a pointer to the local entries at this index */
  size_t base_index = get_entry_index( bucket, soln_idx );
  T *local_entries = &entries[ base_index ];

  local_entries[ choice ] += 1;

  if( local_entries[ choice ] <= 0 ) {
    /* Overflow! */
    return 1;
  }

  return 0;
}
Esempio n. 5
0
void Entries_der<T>::update_regret( const int bucket,
				    const int64_t soln_idx,
				    const int num_choices,
				    const int *values,
				    const int retval )
{
  /* Get a pointer to the local entries at this index */
  size_t base_index = get_entry_index( bucket, soln_idx );
  T *local_entries = &entries[ base_index ];

  for( int c = 0; c < num_choices; ++c ) {
    int diff = values[ c ] - retval;
    T new_regret = local_entries[ c ] + diff;
    /* Only update regret if no overflow occurs */
    if( ( ( diff < 0 ) && ( new_regret < local_entries[ c ] ) )
	|| ( ( diff > 0 ) && ( new_regret > local_entries[ c ] ) ) ) {
      local_entries[ c ] = new_regret;
    }
  }
}
Esempio n. 6
0
uint64_t Entries_der<T>::get_pos_values( const int bucket,
					 const int64_t soln_idx,
					 const int num_choices,
					 uint64_t *values ) const
{
  /* Get the local entries at this index */
  size_t base_index = get_entry_index( bucket, soln_idx );
  T local_entries[ num_choices ];
  memcpy( local_entries, &entries[ base_index ], num_choices * sizeof( T ) );

  /* Zero out negative values and store in the returned array */
  uint64_t sum_values = 0;
  for( int c = 0; c < num_choices; ++c ) {
    local_entries[ c ] *= ( local_entries[ c ] > 0 );
    values[ c ] = local_entries[ c ];
    sum_values += local_entries[ c ];
  }

  return sum_values;
}
Esempio n. 7
0
/* returns -1-index if already exists */
static int add_entry(int insert_at, struct string_list *list, const char *string)
{
	int exact_match = 0;
	int index = insert_at != -1 ? insert_at : get_entry_index(list, string, &exact_match);

	if (exact_match)
		return -1 - index;

	if (list->nr + 1 >= list->alloc) {
		list->alloc += 32;
		REALLOC_ARRAY(list->items, list->alloc);
	}
	if (index < list->nr)
		memmove(list->items + index + 1, list->items + index,
				(list->nr - index)
				* sizeof(struct string_list_item));
	list->items[index].string = list->strdup_strings ?
		xstrdup(string) : (char *)string;
	list->items[index].util = NULL;
	list->nr++;

	return index;
}
Esempio n. 8
0
int string_list_has_string(const struct string_list *list, const char *string)
{
	int exact_match;
	get_entry_index(list, string, &exact_match);
	return exact_match;
}