Exemplo n.º 1
0
static char* find_compare_valid(void) {
  Object* object1 = create_object(1);
  Object* object2 = create_object(1);
  linked_list_append(root, object1);
  mu_assert(0 == linked_list_find_compare(root, object2, object_compare), "Could not find object index by comparison.");
  return 0;
}
Exemplo n.º 2
0
static char* find_compare_invalid(void) {
  Object* object1 = create_object(1);
  Object* object2 = create_object(2);
  linked_list_append(root, object1);
  mu_assert(-1 == linked_list_find_compare(root, object2, object_compare), "Found incorrect object index by comparison.");
  return 0;
}
Exemplo n.º 3
0
int32_t persist_read_int(const uint32_t key) {
  Persist* persist = (Persist*) linked_list_get(persistence, linked_list_find_compare(persistence, fake_persist(key), persist_compare));
  if (! persist) {
    return -1;
  }
  if (NUMBER != persist->type) {
    return -1;
  }
  return persist->number;
}
Exemplo n.º 4
0
int persist_read_data(const uint32_t key, void *buffer, const size_t buffer_size) {
  Persist* persist = (Persist*) linked_list_get(persistence, linked_list_find_compare(persistence, fake_persist(key), persist_compare));
  if (! persist) {
    return -1;
  }
  if (DATA != persist->type) {
    return -1;
  }
  memcpy(buffer, persist->data, buffer_size);
  return buffer_size;
}
Exemplo n.º 5
0
int persist_read_string(const uint32_t key, char *buffer, const size_t buffer_size) {
  Persist* persist = (Persist*) linked_list_get(persistence, linked_list_find_compare(persistence, fake_persist(key), persist_compare));
  if (! persist) {
    return -1;
  }
  if (STRING != persist->type) {
    return -1;
  }
  strncpy(buffer, persist->str, buffer_size);
  return buffer_size;
}
const char *localize_str(int hashval) { 
  hash_string s;
  s.hashval = hashval;
  int16_t index = linked_list_find_compare(s_root, &s, compare_hash_string);
  if(index > -1){
    return ((hash_string*)linked_list_get(s_root, index))->value;
  }
  else {
    char *res = prv_load(hashval);
    if(res){
      if(s_limit > 0){
        uint16_t count = linked_list_count(s_root);
        if(count > s_limit){
          hash_string *last = linked_list_get(s_root, count-1);
          prv_destroy_element(last, NULL);
          linked_list_remove(s_root, count-1);
        }
      }
      return res;
    }
  }
  return "\7"; //return blank character
}
Exemplo n.º 7
0
int16_t linked_list_find(LinkedRoot* root, void* object) {
  return linked_list_find_compare(root, object, pointer_compare);
}
Exemplo n.º 8
0
bool linked_list_contains_compare(LinkedRoot* root, void* object, ObjectCompare compare) {
  return linked_list_find_compare(root, object, compare) >= 0;
}
Exemplo n.º 9
0
status_t persist_delete(uint32_t key) {
  linked_list_remove(persistence, linked_list_find_compare(persistence, fake_persist(key), persist_compare));
  return S_SUCCESS;
}