示例#1
0
文件: map.c 项目: tylerneylon/ccache
map__key_value *map__set(Map map, void *key, void *value) {
  int h = map->hash(key);
  List *entry = find_with_hash(map, key, h);
  map__key_value *pair;
  if (entry) {
    pair = (*entry)->item;
    if (map->key_releaser && pair->key != key) {
      map->key_releaser(pair->key, NULL);
    }
    pair->key = key;
    if (map->value_releaser && pair->value != value) {
      map->value_releaser(pair->value, NULL);
    }
    pair->value = value;
    return pair;
  } else {
    // New pair.
    pair = map->pair_alloc(sizeof(map__key_value));
    pair->key = key;
    pair->value = value;

    double load = (map->count + 1) / (map->buckets->count);
    if (load > MAX_LOAD) double_size(map);

    int n = map->buckets->count;
    int index = ((unsigned int)h) % n;
    List *bucket = (List *)array__item_ptr(map->buckets, index);
    list__insert(bucket, pair);
    map->count++;
  }
  return pair;
}
示例#2
0
文件: l3dd.cpp 项目: glycerine/L3
// for both  dd_del_ith() and dd_ith()
long dd_helper_verify_integer_index(l3obj* ddobj, l3obj* vv, l3path& sexps, Tag* owner, Tag* retown) {
    FILE* ifp = 0;
 
   if (0==ddobj || ddobj->_type != t_ddt) {
       printf("error: dd_ith called on non t_ddt object, in expression '%s'.\n",
              sexps());
       generic_delete(vv, L3STDARGS_OBJONLY);
       l3throw(XABORT_TO_TOPLEVEL);
   }

   l3obj* index = 0;

   ptrvec_get(vv,1,&index);
   if (0==index || index->_type != t_dou || double_size(index) < 1) {
       printf("error: dd_ith called with bad index value, non-numeric, in expression '%s'.\n",
              sexps());
       generic_delete(vv, L3STDARGS_OBJONLY);
       l3throw(XABORT_TO_TOPLEVEL);
   }

   double dindex = double_get(index,0);

   long   as_integer = (long)dindex;
   bool   is_integer = (dindex == (double)as_integer);

   if (!is_integer) {
       printf("error: dd_ith called with bad index value, non-integer index '%.6f', in expression '%s'.\n",
              dindex,
              sexps());
       generic_delete(vv, L3STDARGS_OBJONLY);
       l3throw(XABORT_TO_TOPLEVEL);
   }

   return as_integer;
}
示例#3
0
void
memorize_start () {
  //cout << "Memorize start" << INDENT << LF;
  mem_cur++;
  if (mem_cur == mem_max_pos)
    double_size (mem_pos, mem_max_pos);
  mem_pos[mem_cur]= mem_pos[mem_cur-1];
}
示例#4
0
static void
RegisterRequestName(unsigned major, unsigned minor, char *name)
{
    while (major >= nmajor) {
        if (!double_size(&requests, nmajor, sizeof(char **)))
            return;
        if (!double_size(&nminor, nmajor, sizeof(unsigned)))
            return;
        nmajor = nmajor ? nmajor * 2 : BASE_SIZE;
    }
    while (minor >= nminor[major]) {
        if (!double_size(requests + major, nminor[major], sizeof(char *)))
            return;
        nminor[major] = nminor[major] ? nminor[major] * 2 : BASE_SIZE;
    }

    free(requests[major][minor]);
    requests[major][minor] = name;
}
示例#5
0
文件: registry.c 项目: hush-z/VMGL
static void
RegisterEventName(unsigned event, char *name) {
    while (event >= nevent) {
        if (!double_size(&events, nevent, sizeof(char *)))
            return;
        nevent = nevent ? nevent * 2 : BASE_SIZE;
    }

    free(events[event]);
    events[event] = name;
}
示例#6
0
文件: registry.c 项目: hush-z/VMGL
static void
RegisterErrorName(unsigned error, char *name) {
    while (error >= nerror) {
        if (!double_size(&errors, nerror, sizeof(char *)))
            return;
        nerror = nerror ? nerror * 2 : BASE_SIZE;
    }

    free(errors[error]);
    errors[error] = name;
}
示例#7
0
void
RegisterResourceName(RESTYPE resource, const char *name)
{
    resource &= TypeMask;

    while (resource >= nresource) {
        if (!double_size(&resources, nresource, sizeof(char *)))
            return;
        nresource = nresource ? nresource * 2 : BASE_SIZE;
    }

    resources[resource] = name;
}
示例#8
0
memorizer::memorizer (memorizer_rep* ptr) {
  rep= bigmem_insert (ptr);
  //cout << "construct " << ptr << " -> " << rep << LF;
  if (rep != ptr) tm_delete (ptr);
  //cout << "  set " << mem_pos[mem_cur] << ": " << rep << LF;
  memorizer_rep*& old_rep (mem_stack[mem_pos[mem_cur]++].rep);
  if (rep == old_rep) rep->ref_count++;
  else {
    if (old_rep != NULL) {
      old_rep->ref_count--;
      if (old_rep->ref_count == 0) tm_delete (old_rep);
    }
    old_rep= rep;
    rep->ref_count += 2;
  }
  if (mem_pos[mem_cur] == mem_max_stack)
    double_size (mem_stack, mem_max_stack);
}
示例#9
0
  // Double the size of the hash and return false. Unless all the
  // thread have reported they are done, in which case do nothing and
  // return true.
  bool handle_full_ary() {
    bool serial_thread = size_barrier_.wait();
    if(done_threads_ >= nb_threads_) // All done?
      return true;

    bool success = false;
    if(do_size_doubling_)
      success = success || double_size(serial_thread);

    if(!success && dumper_) {
      if(serial_thread)
        dumper_->dump(ary_);
      success = true;
      size_barrier_.wait();
    }

    if(!success)
      throw std::runtime_error("Hash full");

    return false;
  }
示例#10
0
void MainWindow::create_actions()
{
    // file menu

    new_model_action = new QAction(tr("New voxel model"), this);
    connect(new_model_action, SIGNAL(triggered()), this, SLOT(new_model()));
 
    open_model_action = new QAction(tr("Open voxel model"), this);
    connect(open_model_action, SIGNAL(triggered()), this, SLOT(open_model()));

    clone_model_action = new QAction(tr("Clone voxel model"), this);
    connect(clone_model_action, SIGNAL(triggered()), this, SLOT(clone_model()));
 
    save_action = new QAction(tr("&Save"), this);
    save_action->setShortcuts(QKeySequence::Save);
    connect(save_action, SIGNAL(triggered()), this, SLOT(save()));
 
    save_as_action = new QAction(tr("Save &As..."), this);
    save_as_action->setShortcuts(QKeySequence::SaveAs);
    connect(save_as_action, SIGNAL(triggered()), this, SLOT(save_as()));
 
    exit_action = new QAction(tr("E&xit"), this);
    exit_action->setShortcuts(QKeySequence::Quit);
    exit_action->setStatusTip(tr("Exit the application"));
    connect(exit_action, SIGNAL(triggered()), qApp, SLOT(closeAllWindows()));
 
/*        cut_action = new QAction(tr("Cu&t"), this);
    cut_action->setShortcuts(QKeySequence::Cut);
    cut_action->setStatusTip(tr("Cut the current selection's contents to the "
                            "clipboard"));
    connect(cut_action, SIGNAL(triggered()), this, SLOT(cut()));
 
    copy_action = new QAction(tr("&Copy"), this);
    copy_action->setShortcuts(QKeySequence::Copy);
    copy_action->setStatusTip(tr("Copy the current selection's contents to the "
                             "clipboard"));
    connect(copy_action, SIGNAL(triggered()), this, SLOT(copy()));
 
    paste_action = new QAction(tr("&Paste"), this);
    paste_action->setShortcuts(QKeySequence::Paste);
    paste_action->setStatusTip(tr("Paste the clipboard's contents into the current "
                              "selection"));
    connect(paste_action, SIGNAL(triggered()), this, SLOT(paste()));*/

    // model menu

    double_size_action = new QAction(tr("Double size"), this);
    // new_action->setShortcuts(QKeySequence::New);
    connect(double_size_action, SIGNAL(triggered()), this, 
        SLOT(double_size()));
 
    half_size_action = new QAction(tr("Half size"), this);
    // open_action->setShortcuts(QKeySequence::Open);
    connect(half_size_action, SIGNAL(triggered()), this, 
        SLOT(half_size()));
 
    optimize_action = new QAction(tr("Optimize dimensions"), this);
    // save_action->setShortcuts(QKeySequence::Save);
    connect(optimize_action, SIGNAL(triggered()), this,
        SLOT(optimize()));

    rotate_action = new QAction(tr("Rotate 90 degrees"), this);
    // save_action->setShortcuts(QKeySequence::Save);
    connect(rotate_action, SIGNAL(triggered()), this,
        SLOT(rotate()));

}
示例#11
0
文件: mhash.c 项目: 66laps/4store
int fs_mhash_put(fs_mhash *mh, const fs_rid rid, fs_index_node val)
{
    int entry = FS_MHASH_ENTRY(mh, rid);
    fs_mhash_entry e;
    int candidate = -1;
    for (int i=0; 1; i++) {
        e.rid = 0;
        e.val = 0;
        if (pread(mh->fd, &e, sizeof(e), sizeof(struct mhash_header) +
                  entry * sizeof(e)) == -1) {
            fs_error(LOG_CRIT, "read from %s failed: %s", mh->filename,
                     strerror(errno));

            return 1;
        }
        if (e.rid == rid) {
            /* model is allready there, replace value */

            break;
        } else if (e.rid == 0 && candidate == -1) {
            /* we can't break here because there might be a mathcing entry
             * later in the hashtable */
            candidate = entry;
        }
        if ((i == mh->search_dist || entry == mh->size - 1) &&
                candidate != -1) {
            /* we can use the candidate we found earlier */
            entry = candidate;
            if (pread(mh->fd, &e, sizeof(e), sizeof(struct mhash_header) +
                      entry * sizeof(e)) == -1) {
                fs_error(LOG_CRIT, "read from %s failed: %s", mh->filename,
                         strerror(errno));

                return 1;
            }

            break;
        }
        if (i == mh->search_dist || entry == mh->size - 1) {
            /* model hash overful, grow */
            double_size(mh);

            return fs_mhash_put(mh, rid, val);
        }
        entry++;
    }

    /* if there's no changes to be made we don't want to write anything */
    if (e.rid == rid && e.val == val) return 0;

    fs_index_node oldval = e.val;

    e.rid = rid;
    e.val = val;
    if (pwrite(mh->fd, &e, sizeof(e), sizeof(struct mhash_header) +
               entry * sizeof(e)) == -1) {
        fs_error(LOG_CRIT, "write to %s failed: %s", mh->filename,
                 strerror(errno));

        return 1;
    }
    if (val) {
        if (!oldval) mh->count++;
    } else {
        if (oldval) mh->count--;
    }

    return 0;
}