コード例 #1
0
ファイル: blockinlining.c プロジェクト: RWB01/Code-Translator
static NODE *
new_assign(NODE * lnode, NODE * rhs)
{
    switch (nd_type(lnode)) {
      case NODE_LASGN:{
	  return NEW_NODE(NODE_LASGN, lnode->nd_vid, rhs, lnode->nd_cnt);
	  /* NEW_LASGN(lnode->nd_vid, rhs); */
      }
      case NODE_GASGN:{
	  return NEW_GASGN(lnode->nd_vid, rhs);
      }
      case NODE_DASGN:{
	  return NEW_DASGN(lnode->nd_vid, rhs);
      }
      case NODE_ATTRASGN:{
	  NODE *args = 0;
	  if (lnode->nd_args) {
	      args = NEW_ARRAY(lnode->nd_args->nd_head);
	      args->nd_next = NEW_ARRAY(rhs);
	      args->nd_alen = 2;
	  }
	  else {
	      args = NEW_ARRAY(rhs);
	  }

	  return NEW_ATTRASGN(lnode->nd_recv,
			      lnode->nd_mid,
			      args);
      }
      default:
	rb_bug("unimplemented (block inlining): %s", ruby_node_name(nd_type(lnode)));
    }
    return 0;
}
コード例 #2
0
ファイル: isometry_cusped.c プロジェクト: DamianHeard/orb
static void copy_isometry(
	Triangulation	*manifold0,
	Triangulation	*manifold1,
	Isometry		**new_isometry)
{
	Tetrahedron	*tet0;
	int			i;

	/*
	 *	Allocate the Isometry.
	 */

	*new_isometry				= NEW_STRUCT(Isometry);
	(*new_isometry)->tet_image	= NEW_ARRAY(manifold0->num_tetrahedra, int);
	(*new_isometry)->tet_map	= NEW_ARRAY(manifold0->num_tetrahedra, Permutation);
	(*new_isometry)->cusp_image	= NEW_ARRAY(manifold0->num_cusps, int);
	(*new_isometry)->cusp_map	= NEW_ARRAY(manifold0->num_cusps, MatrixInt22);
	(*new_isometry)->singular_image	= NEW_ARRAY(manifold0->num_singular_arcs, int);

	/*
	 *	Set the num_tetrahedra and num_cusps fields.
	 */

	(*new_isometry)->num_tetrahedra		= manifold0->num_tetrahedra;
	(*new_isometry)->num_cusps		= manifold0->num_cusps;
	(*new_isometry)->num_singular_arcs	= manifold0->num_singular_arcs;

	/*
	 *	Copy the isometry from the Triangulation
	 *	to the Isometry data structure.
	 */

	for (tet0 = manifold0->tet_list_begin.next, i = 0;
		 tet0 != &manifold0->tet_list_end;
		 tet0 = tet0->next, i++)
	{
		(*new_isometry)->tet_image[i]	= tet0->image->index;
		(*new_isometry)->tet_map[i]		= tet0->map;
	}

	/*
	 *	How does this Isometry act on the Cusps?
	 */

	compute_cusp_action(manifold0, manifold1, *new_isometry);

	compute_singular_action(manifold0, *new_isometry);

	/*
	 *	We don't use the "next" field.
	 */

	(*new_isometry)->next = NULL;
}
コード例 #3
0
ファイル: bmsearch.cpp プロジェクト: venkatarajasekhar/Qt
BadCharacterTable::BadCharacterTable(CEList &patternCEs, CollData *data, UErrorCode &status)
    : minLengthCache(NULL)
{
    int32_t plen = patternCEs.size();

    // **** need a better way to deal with this ****
    if (U_FAILURE(status) || plen == 0) {
        return;
    }

    int32_t *history = NEW_ARRAY(int32_t, plen);

    if (history == NULL) {
        status = U_MEMORY_ALLOCATION_ERROR;
        return;
    }

    for (int32_t i = 0; i < plen; i += 1) {
        history[i] = -1;
    }

    minLengthCache = NEW_ARRAY(int32_t, plen + 1);

    if (minLengthCache == NULL) {
        DELETE_ARRAY(history);
        status = U_MEMORY_ALLOCATION_ERROR;
        return;
    }

    maxSkip = minLengthCache[0] = data->minLengthInChars(&patternCEs, 0, history);

    for(int32_t j = 0; j < HASH_TABLE_SIZE; j += 1) {
        badCharacterTable[j] = maxSkip;
    }

    for(int32_t p = 1; p < plen; p += 1) {
        minLengthCache[p] = data->minLengthInChars(&patternCEs, p, history);

        // Make sure this entry is not bigger than the previous one.
        // Otherwise, we might skip too far in some cases.
        if (minLengthCache[p] < 0 || minLengthCache[p] > minLengthCache[p - 1]) {
            minLengthCache[p] = minLengthCache[p - 1];
        }
    }

    minLengthCache[plen] = 0;

    for(int32_t p = 0; p < plen - 1; p += 1) {
        badCharacterTable[hash(patternCEs[p])] = minLengthCache[p + 1];
    }

    DELETE_ARRAY(history);
}
コード例 #4
0
ファイル: GEObjeto3D.cpp プロジェクト: EQ4/neonv2
//---------------------------------------------------------------------------//
// PreparaBatches
//
//---------------------------------------------------------------------------//
void CObjeto3D::PreparaBatches(int *pTraductorMateriales, int iNumMateriales)
{
    m_iNumBatches = iNumMateriales;
    m_pBatches = NEW_ARRAY(TFaceBatch, iNumMateriales);
    for (int i = 0; i < iNumMateriales; i++)
    {
        m_pBatches[i].iMat      = -1;
        m_pBatches[i].uNumFaces = 0;
        m_pBatches[i].pFaces    = NULL;
        int uNumFaces = 0;
        for (int j = 0; j < m_uNumFaces; j++)
        {
            if (m_pFaces[j].iMat == i)
                uNumFaces++;
        }
        // Hay faces, guardar el batch
        if (uNumFaces > 0)
        {
            m_pBatches[i].iMat      = pTraductorMateriales[i];
            m_pBatches[i].uNumFaces = uNumFaces;
            m_pBatches[i].pFaces    = NEW_ARRAY(int, uNumFaces);
            int iFace = 0;
            for (int j = 0; j < m_uNumFaces; j++)
            {
                if (m_pFaces[j].iMat == i)
                    m_pBatches[i].pFaces[iFace++] = j;
            }
        }
    }
コード例 #5
0
ファイル: list.c プロジェクト: richcole/game
void list_init(struct list_t *lst, uint32_t element_size, uint32_t len) {
    lst->data = NEW_ARRAY(uint8_t, element_size * len);
    lst->len = len;
    lst->tail = 0;
    lst->element_size = element_size;
    memset(lst->data, 0, element_size * len);
}
コード例 #6
0
ファイル: ucoleitr.cpp プロジェクト: winlibs/icu4c
void RCEBuffer::put(uint32_t ce, int32_t ixLow, int32_t ixHigh, UErrorCode &errorCode)
{
    if (U_FAILURE(errorCode)) {
        return;
    }
    if (bufferIndex >= bufferSize) {
        RCEI *newBuffer = NEW_ARRAY(RCEI, bufferSize + BUFFER_GROW);
        if (newBuffer == NULL) {
            errorCode = U_MEMORY_ALLOCATION_ERROR;
            return;
        }

        ARRAY_COPY(newBuffer, buffer, bufferSize);

        if (buffer != defaultBuffer) {
            DELETE_ARRAY(buffer);
        }

        buffer = newBuffer;
        bufferSize += BUFFER_GROW;
    }

    buffer[bufferIndex].ce   = ce;
    buffer[bufferIndex].low  = ixLow;
    buffer[bufferIndex].high = ixHigh;

    bufferIndex += 1;
}
コード例 #7
0
ファイル: counter.c プロジェクト: Jeky/graph
DegNode *countDegree(const char *filename, int nodeCount, int sortBy){
    DegNode *nodes;
    double totalTime;
    int i;

    NEW_ARRAY(nodes, DegNode, nodeCount);
    for(i = 0; i < nodeCount; i++){
        nodes[i].index = i;
        nodes[i].inDeg = 0;
        nodes[i].outDeg = 0;
    }

    logMsg("Start Counting Degree in Graph From File: %s.\n", filename);
    totalTime = loadGraphFile(nodes, filename, &degreeCounter);

    logMsg("Finish Counting Degree. Total Time: %0.2lf sec.\n", totalTime);
    switch(sortBy){
        case SORT_BY_INDEG:
            logMsg("Sort Degree by Indegree...\n");
            qsort(nodes, nodeCount, sizeof(DegNode), indegreeComparator);
            break;
        case SORT_BY_OUTDEG:
            logMsg("Sort Degree by Outdegree...\n");
            qsort(nodes, nodeCount, sizeof(DegNode), outdegreeComparator);
            break;
    }

    return nodes;
}
コード例 #8
0
ファイル: csdetect.cpp プロジェクト: mason105/red5cpp
U_CAPI  UEnumeration * U_EXPORT2
ucsdet_getAllDetectableCharsets(const UCharsetDetector *ucsd,  UErrorCode *status)
{
    if(U_FAILURE(*status)) {
        return 0;
    }

    /* Initialize recognized charsets. */
    CharsetDetector::getDetectableCount();

    UEnumeration *en = NEW_ARRAY(UEnumeration, 1);
    memcpy(en, &gCSDetEnumeration, sizeof(UEnumeration));
    en->context = (void*)NEW_ARRAY(Context, 1);
    uprv_memset(en->context, 0, sizeof(Context));
    return en;
}
コード例 #9
0
ファイル: colldata.cpp プロジェクト: icu-project/icu4c
void CEList::add(uint32_t ce, UErrorCode &status)
{
    if (U_FAILURE(status)) {
        return;
    }

    if (listSize >= listMax) {
        int32_t newMax = listMax + CELIST_BUFFER_SIZE;
        uint32_t *newCEs = NEW_ARRAY(uint32_t, newMax);

        if (newCEs == NULL) {
            status = U_MEMORY_ALLOCATION_ERROR;
            return;
        }

        uprv_memcpy(newCEs, ces, listSize * sizeof(uint32_t));

        if (ces != ceBuffer) {
            DELETE_ARRAY(ces);
        }

        ces = newCEs;
        listMax = newMax;
    }

    ces[listSize++] = ce;
}
コード例 #10
0
ファイル: blockinlining.c プロジェクト: RWB01/Code-Translator
static NODE *
new_ary(NODE * head, NODE * tail)
{
    head = NEW_ARRAY(head);
    head->nd_next = tail;
    return head;
}
コード例 #11
0
ファイル: sql_mvc.c プロジェクト: f7753/monetdb
mvc *
mvc_create(int clientid, backend_stack stk, int debug, bstream *rs, stream *ws)
{
	int i;
	mvc *m;

 	m = ZNEW(mvc);
	if (mvc_debug)
		fprintf(stderr, "#mvc_create\n");

	m->errstr[0] = '\0';
	/* if an error exceeds the buffer we don't want garbage at the end */
	m->errstr[ERRSIZE-1] = '\0';

	m->qc = qc_create(clientid, 0);
	m->sa = NULL;

	m->params = NULL;
	m->sizevars = MAXPARAMS;
	m->vars = NEW_ARRAY(sql_var, m->sizevars);
	m->topvars = 0;
	m->frame = 1;
	m->use_views = 0;
	m->argmax = MAXPARAMS;
	m->args = NEW_ARRAY(atom*,m->argmax);
	m->argc = 0;
	m->sym = NULL;

	m->rowcnt = m->last_id = m->role_id = m->user_id = -1;
	m->timezone = 0;
	m->clientid = clientid;

	m->emode = m_normal;
	m->emod = mod_none;
	m->reply_size = 100;
	m->debug = debug;
	m->cache = DEFAULT_CACHESIZE;
	m->caching = m->cache;
	m->history = 0;

	m->label = 0;
	m->cascade_action = NULL;
	for(i=0;i<MAXSTATS;i++)
		m->opt_stats[i] = 0;

	store_lock();
	m->session = sql_session_create(stk, 1 /*autocommit on*/);
	store_unlock();

	m->type = Q_PARSE;
	m->pushdown = 1;

	m->result_id = 0;
	m->results = NULL;

	scanner_init(&m->scanner, rs, ws);
	return m;
}
コード例 #12
0
void it_init() {
  global_it.table_size = INITIAL_IT_SIZE;
  global_it.num_ins = 0;
  global_it.instruction_ids = NEW_ARRAY(global_it.instruction_ids,
      global_it.table_size, InsEntry)
  global_it.ins_ht = hashtable_create(TABLE_SZ * 8);
  register_instructions_here();

}
コード例 #13
0
ファイル: list.c プロジェクト: richcole/game
void list_push(struct list_t *lst, void *element) {
    if ( lst->tail < lst->len ) {
        memcpy(lst->data + lst->tail + 1, element, lst->element_size);
    } else {
        void *new_data = NEW_ARRAY(uint8_t, lst->element_size * lst->len * 2);
        lst->len *= 2;
        memcpy(new_data, lst->data, lst->element_size * lst->len);
        free(lst->data);
        lst->data = new_data;
    }
}
コード例 #14
0
ファイル: inputext.cpp プロジェクト: icu-project/icu4c
U_NAMESPACE_BEGIN

#define BUFFER_SIZE 8192

#define NEW_ARRAY(type,count) (type *) uprv_malloc((count) * sizeof(type))
#define DELETE_ARRAY(array) uprv_free((void *) (array))

InputText::InputText(UErrorCode &status)
    : fInputBytes(NEW_ARRAY(uint8_t, BUFFER_SIZE)), // The text to be checked.  Markup will have been
                                                 //   removed if appropriate.
      fByteStats(NEW_ARRAY(int16_t, 256)),       // byte frequency statistics for the input text.
                                                 //   Value is percent, not absolute.
      fDeclaredEncoding(0),
      fRawInput(0),
      fRawLength(0)
{
    if (fInputBytes == NULL || fByteStats == NULL) {
        status = U_MEMORY_ALLOCATION_ERROR;
    }
}
コード例 #15
0
ファイル: cgnomelayout.c プロジェクト: icu-project/icu4c
GtkWidget *newSample(const gchar *fileName)
{
  Context *context = NEW_ARRAY(Context, 1);
  gchar *title;
  GtkWidget *app;
  GtkWidget *area;
  GtkStyle *style;
  int i;

  context->width  = 600;
  context->height = 400;
  context->paragraph = pf_factory(fileName, font, guiSupport);

  title = prettyTitle(fileName);
  app = gnome_app_new("gnomeLayout", title);

  gtk_object_set_data(GTK_OBJECT(app), "context", context);

  gtk_window_set_default_size(GTK_WINDOW(app), 600 - 24, 400);

  gnome_app_create_menus_with_data(GNOME_APP(app), mainMenu, app);

  gtk_signal_connect(GTK_OBJECT(app), "delete_event",
             GTK_SIGNAL_FUNC(eventDelete), NULL);

  area = gtk_drawing_area_new();
  gtk_object_set_data(GTK_OBJECT(app), "area", area);

  style = gtk_style_copy(gtk_widget_get_style(area));

  for (i = 0; i < 5; i += 1) {
    style->fg[i] = style->white;
  }
    
  gtk_widget_set_style(area, style);

  gnome_app_set_contents(GNOME_APP(app), area);

  gtk_signal_connect(GTK_OBJECT(area),
             "expose_event",
             GTK_SIGNAL_FUNC(eventExpose),
             context);

  gtk_signal_connect(GTK_OBJECT(area),
             "configure_event",
             GTK_SIGNAL_FUNC(eventConfigure),
             context);

  appList = g_slist_prepend(appList, app);

  g_free(title);

  return app;
}
コード例 #16
0
ファイル: work_queue.c プロジェクト: ncdc/qpid
static void allocate_batch(work_queue_t *w)
{
    int i;
    work_item_t *batch = NEW_ARRAY(work_item_t, BATCH_SIZE);
    if (!batch)
        return;

    memset(batch, 0, sizeof(work_item_t) * BATCH_SIZE);

    for (i = 0; i < BATCH_SIZE; i++)
        DEQ_INSERT_TAIL(w->free_list, &batch[i]);
}
コード例 #17
0
ファイル: colldata.cpp プロジェクト: icu-project/icu4c
int32_t CollData::minLengthInChars(const CEList *ceList, int32_t offset) const
{
    int32_t clength = ceList->size();
    int32_t *history = NEW_ARRAY(int32_t, clength);

    for (int32_t i = 0; i < clength; i += 1) {
        history[i] = -1;
    }

    int32_t minLength = minLengthInChars(ceList, offset, history);

    DELETE_ARRAY(history);

    return minLength;
}
コード例 #18
0
ファイル: GEObjeto3D.cpp プロジェクト: EQ4/neonv2
//---------------------------------------------------------------------------//
// CalculaUV
//
//---------------------------------------------------------------------------//
void CObjeto3D::CalculaUV(D3DXMATRIX const &matProj)
{
    if ((m_iRenderMode == RENDER_ENVMAP) || m_bUseUVEnvMap)
    {
        TVector2 *pUV = NEW_ARRAY(TVector2, m_uNumVertices);
        D3DXMATRIX matWVP = m_CacheMatrixRot * matProj;
        for (int i = 0; i < m_uNumVertices; i++)
        {
            TVector3 vSrc = m_pCacheVNormales[i];
            pUV[i].x = matWVP.m[0][0] * vSrc.x +
                       matWVP.m[1][0] * vSrc.y +
                       matWVP.m[2][0] * vSrc.z;
            pUV[i].y = matWVP.m[0][1] * vSrc.x +
                       matWVP.m[1][1] * vSrc.y +
                       matWVP.m[2][1] * vSrc.z;
            pUV[i].x = pUV[i].x * 0.5f + 0.5f;
            pUV[i].y = pUV[i].y * 0.5f + 0.5f;
        }
        for (int i = 0; i < m_uNumFaces; i++)
        {
            m_pCacheUVEnvMap[i*3+0] = pUV[m_pFaces[i].i0];
            m_pCacheUVEnvMap[i*3+1] = pUV[m_pFaces[i].i1];
            m_pCacheUVEnvMap[i*3+2] = pUV[m_pFaces[i].i2];
        }
        DISPOSE_ARRAY(pUV);
    }

    if ((m_iRenderMode == RENDER_ENVMAPFLAT) || m_bUseUVEnvMapFlat)
    {
        D3DXMATRIX matWVP = m_CacheMatrixRot * matProj;
        for (int i = 0; i < m_uNumFaces; i++)
        {
            TVector3 vSrc = m_pCacheFNormales[i];
            TVector2 uv;
            uv.x = matWVP.m[0][0] * vSrc.x +
                   matWVP.m[1][0] * vSrc.y +
                   matWVP.m[2][0] * vSrc.z;
            uv.y = matWVP.m[0][1] * vSrc.x +
                   matWVP.m[1][1] * vSrc.y +
                   matWVP.m[2][1] * vSrc.z;
            uv.x = uv.x * 0.5f + 0.5f;
            uv.y = uv.y * 0.5f + 0.5f;
            m_pCacheUVEnvMapFlat[i*3+0] = uv;
            m_pCacheUVEnvMapFlat[i*3+1] = uv;
            m_pCacheUVEnvMapFlat[i*3+2] = uv;
        }
    }
}
コード例 #19
0
ファイル: bmsearch.cpp プロジェクト: venkatarajasekhar/Qt
Target::Target(UCollator *theCollator, const UnicodeString *target, int32_t patternLength, UErrorCode &status)
    : bufferSize(0), bufferMin(0), bufferMax(0),
      strengthMask(0), strength(UCOL_PRIMARY), variableTop(0), toShift(FALSE), coll(theCollator),
      nfd(*Normalizer2Factory::getNFDInstance(status)),
      targetString(NULL), targetBuffer(NULL), targetLength(0), elements(NULL), charBreakIterator(NULL)
{
    strength = ucol_getStrength(coll);
    toShift = ucol_getAttribute(coll, UCOL_ALTERNATE_HANDLING, &status) ==  UCOL_SHIFTED;
    variableTop = ucol_getVariableTop(coll, &status);

    // find the largest expansion
    uint8_t maxExpansion = 0;
    for (const uint8_t *expansion = coll->expansionCESize; *expansion != 0; expansion += 1) {
        if (*expansion > maxExpansion) {
            maxExpansion = *expansion;
        }
    }

    // room for an extra character on each end, plus 4 for safety
    bufferSize = patternLength + (2 * maxExpansion) + 4;

    ceb = NEW_ARRAY(CEI, bufferSize);

    if (ceb == NULL) {
        status = U_MEMORY_ALLOCATION_ERROR;
        return;
    }

    if (target != NULL) {
        setTargetString(target);
    }

    switch (strength)
    {
    default:
        strengthMask |= UCOL_TERTIARYORDERMASK;
        /* fall through */

    case UCOL_SECONDARY:
        strengthMask |= UCOL_SECONDARYORDERMASK;
        /* fall through */

    case UCOL_PRIMARY:
        strengthMask |= UCOL_PRIMARYORDERMASK;
    }
}
コード例 #20
0
ファイル: IndexReader.cpp プロジェクト: sdgdsffdsfff/kingso
IndexTerm * IndexReader::getTerm(MemPool* pMemPool, uint64_t fieldNameSign, uint64_t termSign)
{
    if (fieldNameSign == _nidSign) {
        IndexTermInfo* pTermInfo = NEW(pMemPool, IndexTermInfo);
        if(NULL == pTermInfo) {
            return NULL;
        }

        DocIdManager* pDocIdx = DocIdManager::getInstance();
        uint32_t doc = pDocIdx->getDocId(termSign);
        if (doc >= _maxDocNum) {
            pTermInfo->docNum = 0;
            IndexTerm* pTerm = NEW(pMemPool, IndexTerm);
            if(NULL == pTerm) {
                return NULL;
            }
            return pTerm;
        } else {
            pTermInfo->docNum = 1;
            uint32_t* pDocList = NEW_ARRAY(pMemPool, uint32_t, 2);
            IndexUnZipNullOccTerm* pTerm = NEW(pMemPool, IndexUnZipNullOccTerm);
            if (NULL == pTerm || NULL == pDocList) {
                return NULL;
            }
            pDocList[0] = doc;
            pDocList[1] = INVALID_DOCID;
            pTerm->setInvertList((char*)pDocList);
            if (pTerm->init(1, _maxDocNum , 0) < 0) {
                return NULL;
            }
            return pTerm;
        }
    }

    // false find at fieldMap
    util::HashMap<uint64_t, void*>::iterator it = _fieldMap.find(fieldNameSign);
    if (_fieldMap.end() == it) {
        return NULL;
    }
    IndexFieldReader* pReader = (IndexFieldReader*)it->value;
    IndexTerm* pTerm = pReader->getTerm(pMemPool, termSign);
    if(NULL == pTerm) {
        return NEW(pMemPool, IndexTerm);
    }
    return pTerm;
}
コード例 #21
0
ファイル: xmlreader.cpp プロジェクト: Acorld/WinObjC-Heading
static le_uint32 *getHexArray(const UnicodeString &numbers, int32_t &arraySize)
{
    int32_t offset = -1;

    arraySize = 1;
    while((offset = numbers.indexOf(CH_COMMA, offset + 1)) >= 0) {
        arraySize += 1;
    }

    le_uint32 *array = NEW_ARRAY(le_uint32, arraySize);
    char number[16];
    le_int32 count = 0;
    le_int32 start = 0, end = 0;
    le_int32 len = 0;

    // trim leading whitespace
    while(u_isUWhiteSpace(numbers[start])) {
        start += 1;
    }

    while((end = numbers.indexOf(CH_COMMA, start)) >= 0) {
        len = numbers.extract(start, end - start, number, ARRAY_SIZE(number), US_INV);
        number[len] = '\0';
        start = end + 1;

        sscanf(number, "%x", &array[count++]);

        // trim whitespace following the comma
        while(u_isUWhiteSpace(numbers[start])) {
            start += 1;
        }
    }

    // trim trailing whitespace
    end = numbers.length();
    while(u_isUWhiteSpace(numbers[end - 1])) {
        end -= 1;
    }

    len = numbers.extract(start, end - start, number, ARRAY_SIZE(number), US_INV);
    number[len] = '\0';
    sscanf(number, "%x", &array[count]);

    return array;
}
コード例 #22
0
ファイル: hash.c プロジェクト: ted-ross/nexus
hash_t *hash(int bucket_exponent, int batch_size, int value_is_const)
{
    int i;
    hash_t *h = NEW(hash_t);

    if (!h)
        return 0;

    h->bucket_count = 1 << bucket_exponent;
    h->bucket_mask  = h->bucket_count - 1;
    h->batch_size   = batch_size;
    h->size         = 0;
    h->is_const     = value_is_const;
    h->buckets = NEW_ARRAY(bucket_t, h->bucket_count);
    for (i = 0; i < h->bucket_count; i++) {
        DEQ_INIT(h->buckets[i].items);
    }

    return h;
}
コード例 #23
0
void install_current_curve_bases(
    Triangulation   *manifold)
{
    Cusp        *cusp;
    MatrixInt22 *change_matrices;

    /*
     *  Allocate an array to store the change of basis matrices.
     */

    change_matrices = NEW_ARRAY(manifold->num_cusps, MatrixInt22);

    /*
     *  Compute the change of basis matrices.
     */

    for (cusp = manifold->cusp_list_begin.next;
         cusp != &manifold->cusp_list_end;
         cusp = cusp->next)
    {
        if (cusp->index < 0
         || cusp->index >= manifold->num_cusps)
            uFatalError("install_current_curve_bases", "current_curve_basis");

        current_curve_basis_on_cusp(cusp, change_matrices[cusp->index]);
    }

    /*
     *  Install the change of basis matrices.
     */

    if (change_peripheral_curves(manifold, change_matrices) != func_OK)

        uFatalError("install_current_curve_bases", "current_curve_basis");

    /*
     *  Free the array used to store the change of basis matrices.
     */

    my_free(change_matrices);
}
コード例 #24
0
static void attach_extra(
    Triangulation   *manifold)
{
    Tetrahedron *tet;

    for (tet = manifold->tet_list_begin.next;
         tet != &manifold->tet_list_end;
         tet = tet->next)
    {
        /*
         *  Make sure no other routine is using the "extra"
         *  field in the Tetrahedron data structure.
         */
        if (tet->extra != NULL)
            uFatalError("attach_extra", "peripheral_curves");

        /*
         *  Attach the locally defined struct extra.
         */
        tet->extra = NEW_ARRAY(4, Extra);
    }
}
コード例 #25
0
ファイル: cashflow.c プロジェクト: Yuanchu/creditr
/*
***************************************************************************
** Makes a new empty TCashFlowList.
***************************************************************************
*/
TCashFlowList* JpmcdsNewEmptyCFL(int numItems)
{
    static char    routine[]="JpmcdsNewEmptyCFL";
    TCashFlowList *cfl = NULL;
    
    if (numItems < 0)
    {
        JpmcdsErrMsg("%s: # cashflows (%d) must be >= 0.\n", routine, numItems);
        goto done;
    }
    
    cfl = NEW(TCashFlowList);
    if (cfl == NULL)
        goto done;
    
    cfl->fNumItems = numItems;
    if (numItems > 0)
    {
        cfl->fArray = NEW_ARRAY (TCashFlow, numItems);
        if (cfl->fArray == NULL)
            goto done;
    }
    else
    {
        cfl->fArray = NULL;
    }
    /* Success
     */
    return cfl;


  done:
    JpmcdsErrMsg("%s: Failed.\n", routine);
    JpmcdsFreeCFL(cfl);
    return NULL;
}
コード例 #26
0
ファイル: res_table.c プロジェクト: jaiminpan/Monetdb
res_table *
res_table_create(sql_trans *tr, int res_id, int nr_cols, int type, res_table *next, void *O)
{
	BAT *order = (BAT*)O;
	res_table *t = ZNEW(res_table);

	(void) tr;
	t->id = res_id;

	t->query_type = type;
	t->nr_cols = nr_cols;
	t->cur_col = 0;
	t->cols = NEW_ARRAY(res_col, nr_cols);
	memset((char*) t->cols, 0, nr_cols * sizeof(res_col));
	t->tsep = t->rsep = t->ssep = t->ns = NULL;

	t->order = 0;
	if (order) {
		t->order = order->batCacheid;
		bat_incref(t->order);
	} 
	t->next = next;
	return t;
}
コード例 #27
0
ファイル: clayout.c プロジェクト: icu-project/icu4c
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hdc;
    Context *context;
    static le_int32 windowCount = 0;
    static fm_fontMap *fontMap = NULL;
    static rs_surface *surface = NULL;
    static gs_guiSupport *guiSupport = NULL;
    static le_font *font = NULL;

    switch (message) {
    case WM_CREATE:
    {
        LEErrorCode fontStatus = LE_NO_ERROR;

        hdc = GetDC(hwnd);
        guiSupport = gs_gdiGuiSupportOpen();
        surface = rs_gdiRenderingSurfaceOpen(hdc);

        fontMap = fm_gdiFontMapOpen(surface, "FontMap.GDI", 24, guiSupport, &fontStatus);
        font    = le_scriptCompositeFontOpen(fontMap);

        if (LE_FAILURE(fontStatus)) {
            ReleaseDC(hwnd, hdc);
            return -1;
        }

        context = NEW_ARRAY(Context, 1);

        context->width  = 600;
        context->height = 400;

        context->paragraph = pf_factory("Sample.txt", font, guiSupport);
        SetWindowLongPtr(hwnd, 0, (LONG_PTR) context);

        windowCount += 1;
        ReleaseDC(hwnd, hdc);

        PrettyTitle(hwnd, "Sample.txt");
        return 0;
    }

    case WM_SIZE:
    {
        context = (Context *) GetWindowLongPtr(hwnd, 0);
        context->width  = LOWORD(lParam);
        context->height = HIWORD(lParam);

        InitParagraph(hwnd, context);
        return 0;
    }

    case WM_VSCROLL:
    {
        SCROLLINFO si;
        le_int32 vertPos;

        si.cbSize = sizeof si;
        si.fMask = SIF_ALL;
        GetScrollInfo(hwnd, SB_VERT, &si);

        vertPos = si.nPos;

        switch (LOWORD(wParam))
        {
        case SB_TOP:
            si.nPos = si.nMin;
            break;

        case SB_BOTTOM:
            si.nPos = si.nMax;
            break;

        case SB_LINEUP:
            si.nPos -= 1;
            break;

        case SB_LINEDOWN:
            si.nPos += 1;
            break;

        case SB_PAGEUP:
            si.nPos -= si.nPage;
            break;

        case SB_PAGEDOWN:
            si.nPos += si.nPage;
            break;

        case SB_THUMBTRACK:
            si.nPos = si.nTrackPos;
            break;

        default:
            break;
        }

        si.fMask = SIF_POS;
        SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
        GetScrollInfo(hwnd, SB_VERT, &si);

        context = (Context *) GetWindowLongPtr(hwnd, 0);

        if (context->paragraph != NULL && si.nPos != vertPos) {
            ScrollWindow(hwnd, 0, pf_getLineHeight(context->paragraph) * (vertPos - si.nPos), NULL, NULL);
            UpdateWindow(hwnd);
        }

        return 0;
    }

    case WM_PAINT:
    {
        PAINTSTRUCT ps;
        SCROLLINFO si;
        le_int32 firstLine, lastLine;

        hdc = BeginPaint(hwnd, &ps);
        SetBkMode(hdc, TRANSPARENT);

        si.cbSize = sizeof si;
        si.fMask = SIF_ALL;
        GetScrollInfo(hwnd, SB_VERT, &si);

        firstLine = si.nPos;

        context = (Context *) GetWindowLongPtr(hwnd, 0);

        if (context->paragraph != NULL) {
            rs_gdiRenderingSurfaceSetHDC(surface, hdc);

            // NOTE: si.nPos + si.nPage may include a partial line at the bottom
            // of the window. We need this because scrolling assumes that the
            // partial line has been painted.
            lastLine  = min (si.nPos + (le_int32) si.nPage, pf_getLineCount(context->paragraph) - 1);

            pf_draw(context->paragraph, surface, firstLine, lastLine);
        }

        EndPaint(hwnd, &ps);
        return 0;
    }

    case WM_COMMAND:
        switch (LOWORD(wParam)) {
        case IDM_FILE_OPEN:
        {
            OPENFILENAMEA ofn;
            char szFileName[MAX_PATH], szTitleName[MAX_PATH];
            static char szFilter[] = "Text Files (.txt)\0*.txt\0"
                                     "All Files (*.*)\0*.*\0\0";

            ofn.lStructSize       = sizeof (OPENFILENAMEA);
            ofn.hwndOwner         = hwnd;
            ofn.hInstance         = NULL;
            ofn.lpstrFilter       = szFilter;
            ofn.lpstrCustomFilter = NULL;
            ofn.nMaxCustFilter    = 0;
            ofn.nFilterIndex      = 0;
            ofn.lpstrFile         = szFileName;
            ofn.nMaxFile          = MAX_PATH;
            ofn.lpstrFileTitle    = szTitleName;
            ofn.nMaxFileTitle     = MAX_PATH;
            ofn.lpstrInitialDir   = NULL;
            ofn.lpstrTitle        = NULL;
            ofn.Flags             = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
            ofn.nFileOffset       = 0;
            ofn.nFileExtension    = 0;
            ofn.lpstrDefExt       = "txt";
            ofn.lCustData         = 0L;
            ofn.lpfnHook          = NULL;
            ofn.lpTemplateName    = NULL;

            szFileName[0] = '\0';

            if (GetOpenFileNameA(&ofn)) {
                pf_flow *newParagraph;

                hdc = GetDC(hwnd);
                rs_gdiRenderingSurfaceSetHDC(surface, hdc);

                newParagraph = pf_factory(szFileName, font, guiSupport);

                if (newParagraph != NULL) {
                    context = (Context *) GetWindowLongPtr(hwnd, 0);

                    if (context->paragraph != NULL) {
                        pf_close(context->paragraph);
                    }

                    context->paragraph = newParagraph;
                    InitParagraph(hwnd, context);
                    PrettyTitle(hwnd, szTitleName);
                    InvalidateRect(hwnd, NULL, TRUE);

                }
            }

            //ReleaseDC(hwnd, hdc);

            return 0;
        }

        case IDM_FILE_EXIT:
        case IDM_FILE_CLOSE:
            SendMessage(hwnd, WM_CLOSE, 0, 0);
            return 0;

        case IDM_HELP_ABOUTLAYOUTSAMPLE:
            MessageBox(hwnd, TEXT("Windows Layout Sample 0.1\n")
                             TEXT("Copyright (C) 2016 and later: Unicode, Inc. and others. License & terms of use: http://www.unicode.org/copyright.html\n")
                             TEXT("Author: Eric Mader"),
                       szAppName, MB_ICONINFORMATION | MB_OK);
            return 0;

        }
        break;


    case WM_DESTROY:
    {
        context = (Context *) GetWindowLongPtr(hwnd, 0);

        if (context != NULL && context->paragraph != NULL) {
            pf_close(context->paragraph);
        }

        DELETE_ARRAY(context);

        if (--windowCount <= 0) {
            le_fontClose(font);
            rs_gdiRenderingSurfaceClose(surface);
            gs_gdiGuiSupportClose(guiSupport);

            PostQuitMessage(0);
        }

        return 0;
    }

    default:
        return DefWindowProc(hwnd, message, wParam, lParam);
    }

    return 0;
}
コード例 #28
0
ファイル: isometry_cusped.c プロジェクト: DamianHeard/orb
static void find_isometries_which_extend(
	IsometryList	*isometry_list,
	IsometryList	**isometry_list_of_links)
{
	Isometry	*original,
				*copy;
	int			i,
				j,
				k,
				l,
				count;

	/*
	 *	If the isometry_list_of_links isn't needed, don't compute it.
	 */

	if (isometry_list_of_links == NULL)
		return;

	/*
	 *	The function compute_cusped_isometries() (which calls this function)
	 *	has already allocated space for the new IsometryList.
	 *	(It has also intialized the num_isometries and isometry fields,
	 *	but we reinitialize them here just for good form.)
	 */

	/*
	 *	How many Isometries extend to the link?
	 */

	(*isometry_list_of_links)->num_isometries = 0;	/* intentionally redundant */

	for (i = 0; i < isometry_list->num_isometries; i++)

		if (isometry_list->isometry[i]->extends_to_link == TRUE)

			(*isometry_list_of_links)->num_isometries++;

	/*
	 *	If there are no Isometries which extend, set
	 *	(*isometry_list_of_links)->isometry to NULL and return.
	 */

	if ((*isometry_list_of_links)->num_isometries == 0)
	{
		(*isometry_list_of_links)->isometry = NULL;	/* intentionally redundant */

		return;
	}

	/*
	 *	Allocate space for the Isometries which extend to
	 *	Isometries of the associated links, and copy them in.
	 */

	(*isometry_list_of_links)->isometry = NEW_ARRAY((*isometry_list_of_links)->num_isometries, Isometry *);

	for (i = 0, count = 0; i < isometry_list->num_isometries; i++)

		if (isometry_list->isometry[i]->extends_to_link == TRUE)
		{
			(*isometry_list_of_links)->isometry[count] = NEW_STRUCT(Isometry);

			original	= isometry_list->isometry[i];
			copy		= (*isometry_list_of_links)->isometry[count];

			copy->num_tetrahedra	= original->num_tetrahedra;
			copy->num_cusps			= original->num_cusps;
			copy->num_singular_arcs		= original->num_singular_arcs;

			copy->tet_image	= NEW_ARRAY(copy->num_tetrahedra, int);
			copy->tet_map	= NEW_ARRAY(copy->num_tetrahedra, Permutation);
			for (j = 0; j < copy->num_tetrahedra; j++)
			{
				copy->tet_image[j] = original->tet_image[j];
				copy->tet_map  [j] = original->tet_map  [j];
			}

			copy->cusp_image	= NEW_ARRAY(copy->num_cusps, int);
			copy->cusp_map		= NEW_ARRAY(copy->num_cusps, MatrixInt22);
			for (j = 0; j < copy->num_cusps; j++)
			{
				copy->cusp_image[j] = original->cusp_image[j];
				for (k = 0; k < 2; k++)
					for (l = 0; l < 2; l++)
						copy->cusp_map[j][k][l] = original->cusp_map[j][k][l];
			}

			copy->singular_image	= NEW_ARRAY(copy->num_singular_arcs, int);
			for (j=0;j<copy->num_singular_arcs;j++)
				copy->singular_image[j] = original->singular_image[j];

			copy->extends_to_link	= original->extends_to_link;

			count++;
		}
コード例 #29
0
ファイル: MemPool_test.cpp プロジェクト: sdgdsffdsfff/kingso
int main()
{
    // TestCase Group1:
    MemPool objMemPool;
    MemPool *pMemPool = &objMemPool;
    int32_t nCount = 10;
    char *pszArray = NEW_VEC(pMemPool, char, nCount);
    int32_t *pnArray = NEW_VEC(pMemPool, int32_t, nCount);
    float *pfArray = NEW_VEC(pMemPool, float, nCount);
    for (int i = 0; i < nCount; i++) {
        pszArray[i] = 'a' + i;
        pnArray[i] = i;
        pfArray[i] = 1.0 * i;
    }
    for (int i = 0; i < nCount; i++) {
        fprintf(stdout, "pszArray[%d]:\t%c\n", i, pszArray[i]);
        fprintf(stdout, "pnArray[%d]:\t%d\n", i, pnArray[i]);
        fprintf(stdout, "pfArray[%d]:\t%f\n", i, pfArray[i]);
    }
    pMemPool->reset();

    // TestCase Group2:
    MemPool objMemPool2;
    MemPool *pMemPool2 = &objMemPool2;
    int32_t nCount2 = 10;
    MyClass *pMyClass = NEW(pMemPool2, MyClass);
    fprintf(stdout, "pMyClass:\t%d\n", pMyClass->getCount());
    MyClass *pMyClass2 = NEW(pMemPool2, MyClass)(100);
    fprintf(stdout, "pMyClass2:\t%d\n", pMyClass2->getCount());
    MyClass *pMyClassArray = NEW_ARRAY(pMemPool2, MyClass, nCount2);
    for (int i = 0; i < nCount2; i++) {
        fprintf(stdout, "pMyClassArray[%d]:\t%d\n", i, pMyClassArray[i].getCount());
    }
    pMemPool2->reset();

    // TestCase Group3:
    MemPool objMemPool3;
    MemPool *pMemPool3 = &objMemPool3;
    MemMonitor memMonitor(pMemPool3, 1);
    pMemPool3->setMonitor(&memMonitor);
    memMonitor.enableException();
    int32_t nCount3 = 1;
    char *pszArray3 = NEW_VEC(pMemPool3, char, nCount3);
    if (!pszArray3) {
        printf("pszArray3 NEW_VEC Err!\n");
    }
    nCount3 = 1024;
    int32_t *pnArray3 = NEW_VEC(pMemPool3, int32_t, nCount3);
    if (!pnArray3) {
        printf("pnArray3 NEW_VEC Err!\n");
    }
    float *pfArray3 = NEW_VEC(pMemPool3, float, nCount3);
    if (!pfArray3) {
        printf("pfArray3 NEW_VEC Err!\n");
    }
    for (int i = 0; i < nCount3; i++) {
        pszArray3[i] = 'a' + i;
        pnArray3[i] = i;
        pfArray3[i] = 1.0 * i;
    }
    for (int i = 0; i < nCount3; i++) {
        fprintf(stdout, "pszArray3[%d]:\t%c\n", i, pszArray3[i]);
        fprintf(stdout, "pnArray3[%d]:\t%d\n", i, pnArray3[i]);
        fprintf(stdout, "pfArray3[%d]:\t%f\n", i, pfArray3[i]);
    }
    pMemPool3->reset();

    // TestCase Group4:
    MemPool objMemPool4;
    MemPool *pMemPool4 = &objMemPool4;
    MemMonitor memMonitor4(pMemPool4, 1);
    pMemPool4->setMonitor(&memMonitor4);
    memMonitor4.enableException();
    
    int32_t nCountsz4 = 1024;
    char *pszArraysz4 = NEW_VEC(pMemPool4, char, nCountsz4);
    if (!pszArraysz4) {
        printf("pszArraysz4 is NULL\n");
    }
    MyClass *pMyClass4 = NEW(pMemPool4, MyClass);
    if (!pMyClass4) {
        printf("pMyClass4 is NULL\n");
    }
    fprintf(stdout, "pMyClass4:\t%d\n", pMyClass4->getCount());

    int32_t nCountsz4_1 = 1024;
    char *pszArraysz4_1 = NEW_VEC(pMemPool4, char, nCountsz4_1);
    if (!pszArraysz4_1) {
        printf("pszArraysz4_1 is NULL\n");
    }
    MyClass *pMyClass4_1 = NEW(pMemPool4, MyClass)(100);
    if (!pMyClass4_1) {
        printf("pMyClass4_1 is NULL\n");
    }
    fprintf(stdout, "pMyClass4_1:\t%d\n", pMyClass4_1->getCount());
    
    int32_t nCountsz4_2 = 1024;
    char *pszArraysz4_2 = NEW_VEC(pMemPool4, char, nCountsz4_2);
    if (!pszArraysz4_2) {
        printf("pszArraysz4_2 is NULL\n");
    }
    int32_t nCount4_2 = 1;
    MyClass *pMyClassArray4_2 = NEW_ARRAY(pMemPool4, MyClass, nCount4_2);
    if (!pMyClassArray4_2) {
        printf("pMyClassArray4_2 is NULL\n");
    }
    for (int i = 0; i < nCount4_2; i++) {
        fprintf(stdout, "pMyClassArray4_2[%d]:\t%d\n", i, pMyClassArray4_2[i].getCount());
    }
    pMemPool4->reset();

    return 0;
}
コード例 #30
0
ファイル: zerocurve.c プロジェクト: Kevin-Jin/CDS
/*
***************************************************************************
** Build zero curve from money market, and swap instruments.
***************************************************************************
*/
EXPORT TCurve* JpmcdsBuildIRZeroCurve(
    TDate      valueDate,       /* (I) Value date                       */
    char      *instrNames,      /* (I) Array of 'M' or 'S'              */
    TDate     *dates,           /* (I) Array of swaps dates             */
    double    *rates,           /* (I) Array of swap rates              */
    long       nInstr,          /* (I) Number of benchmark instruments  */
    long       mmDCC,           /* (I) DCC of MM instruments            */
    long       fixedSwapFreq,   /* (I) Fixed leg freqency               */
    long       floatSwapFreq,   /* (I) Floating leg freqency            */
    long       fixedSwapDCC,    /* (I) DCC of fixed leg                 */
    long       floatSwapDCC,    /* (I) DCC of floating leg              */
    long       badDayConv,      /* (I) Bad day convention               */
    char      *holidayFile)     /* (I) Holiday file                     */
{
    static char routine[] = "BuildIRZeroCurve";
    int         status    = FAILURE;

    int     i;
    int     nCash = 0;
    int     nSwap = 0;
    char    fwdLength = '3';   /* not used */
    char    instr;

    TDate  *cashDates    = NULL;
    TDate  *swapDates    = NULL;
    double *cashRates    = NULL;
    double *swapRates    = NULL;
    TCurve *zcurveIni    = NULL;
    TCurve *zcurveCash   = NULL;
    TCurve *zcurveSwap   = NULL;

    /* Allocate enough spaces for cash and swap dates/rates */
    cashDates  = NEW_ARRAY(TDate,  nInstr);
    swapDates  = NEW_ARRAY(TDate,  nInstr);
    cashRates  = NEW_ARRAY(double, nInstr);
    swapRates  = NEW_ARRAY(double, nInstr);

    if (cashDates  == NULL || swapDates  == NULL || cashRates  == NULL || swapRates  == NULL)
        goto done;


    /* Sort out cash and swap separately */
    for(i = 0; i < nInstr; i++)
    {
        instr = toupper(instrNames[i]);
        if (instr != JpmcdsMONEYNAME && instr != JpmcdsSWAPNAME)
        {
            JpmcdsErrMsg("%s: unknown instrument type (%c)."
                      " Only (M)oney market or (S)wap is allowed.\n",
                      routine, instrNames[i]);
            goto done;
        }

        if (instr == JpmcdsMONEYNAME)
        {    /* MM Rate */
            cashDates[nCash]  = dates[i];
            cashRates[nCash]  = rates[i];
            nCash++;
        }
        else        /* Swap Rate */
        {
            swapDates[nSwap]  = dates[i];
            swapRates[nSwap]  = rates[i];
            nSwap++;
        }
    }



    /* Initialize the zero curve */
    zcurveIni = JpmcdsNewTCurve(valueDate, 0, (double) 1L, JPMCDS_ACT_365F);
    if (zcurveIni == NULL){
        goto done;
	printf("zcurveIni...\n");
    }

    /* Cash instruments */
    zcurveCash = JpmcdsZCCash(zcurveIni, cashDates, cashRates, nCash, mmDCC);
    if (zcurveCash == NULL){
	JpmcdsErrMsg("Cash Curve not available ... \n");
        goto done;
    }

    /* Swap instruments */
    zcurveSwap = JpmcdsZCSwaps(zcurveCash,
                            NULL,   /* discZC */
                            swapDates,
                            swapRates,
                            nSwap,
                            fixedSwapFreq,
                            floatSwapFreq,
                            fixedSwapDCC,
                            floatSwapDCC,
                            fwdLength,
                            badDayConv,
                            holidayFile);
    if (zcurveSwap == NULL){
      JpmcdsErrMsg("IR curve not available ... \n");
      // printf("g...\n");
      goto done;
    }
    status = SUCCESS;

 done:
    FREE(cashDates);
    FREE(cashRates);
    FREE(swapDates);
    FREE(swapRates);
    JpmcdsFreeTCurve(zcurveIni);
    JpmcdsFreeTCurve(zcurveCash);
    if (status != SUCCESS)
    {
        JpmcdsFreeTCurve(zcurveSwap);
        zcurveSwap = NULL;
        JpmcdsErrMsgFailure(routine);
    }
    return (zcurveSwap);
}