Ejemplo n.º 1
0
// ********************************************************************
// *
// *            mdlAux/2
// *            --------
// *
// *     computes part of the mdl code len for  construct 
// *
// *********************************************************************
double construct::mdlAux(constructNode *Node) 
{
   switch(Node->nodeType)
   { 
      case cnAND:
      case cnPLUS:
      case cnTIMES:
         return mdlAux(Node->left) + mdlAux(Node->right) ;

      case cnCONTattribute: // summing and multiplying
         return mlog2((double)(gFT->noNumeric-1)) ;
      
      case cnCONTattrValue:
      {
        double intValue = gFT->valueInterval[Node->attrIdx]/gFT->opt->mdlErrorPrecision ;
        if (intValue < 1.0)
          intValue = 1.0 ;
        return  mlog2((double)gFT->noAttr) + 2*mlog2((double)intValue) ;
      }
      case  cnDISCattrValue:
        return mlog2((double)gFT->noAttr) +
               mlog2((double)gFT->AttrDesc[gFT->DiscIdx[Node->attrIdx]].NoValues) ;

      case cnDISCattribute:
      default: 
         merror("construct::mdlAux", "unexpected use") ;
         return 0.0 ;
   }
}
Ejemplo n.º 2
0
bool heap_buddy_dealloc_c (struct heap_buddy* pheap, void* buff) {
	struct block_c *pbc    = block_com_from_data(buff);
	struct heap_buddy_block *pb = container_of(pbc, struct heap_buddy_block, common);
	struct block_c *prev   = block_com_prev_adj(pbc);
	struct block_c *next   = block_com_next_adj(pbc);
	int bit = 0;

	if (buff == NULL) {
		return true;
	}

	if (!block_com_valid(pbc)) {
		/* dealloc an invalid block, break it. */
		dbg_assert(false);
	}

	if (block_com_free(pbc)) {
		/* we are try to dealloc the buff twice, handle this situation. */
		return false;
	}

	if (block_com_valid(prev) && block_com_free(prev)) {
		if (block_com_valid(next) && block_com_free(next)) {
			struct heap_buddy_block *b_prev = container_of(prev, struct heap_buddy_block, common);
			struct heap_buddy_block *b_next = container_of(next, struct heap_buddy_block, common);
			dbg_assert((void*)b_prev == (void*)prev);
			dbg_assert((void*)b_next == (void*)next);

			bit = mlog2(block_com_data_size(prev));
			blink_pop(&pheap->buddy[bit], &b_prev->link);
			bit = mlog2(block_com_data_size(next));
			blink_pop(&pheap->buddy[bit], &b_next->link);

			block_com_merge(prev, next);

			bit = mlog2(block_com_data_size(prev));
			blink_push(&pheap->buddy[bit], &b_prev->link);

			block_com_set_free(prev, true);
		}
		else {
			struct heap_buddy_block *b_prev = container_of(prev, struct heap_buddy_block, common);
			dbg_assert((void*)b_prev == (void*)prev);

			bit = mlog2(block_com_data_size(prev));
			blink_pop(&pheap->buddy[bit], &b_prev->link);

			block_com_merge(prev, pbc);

			bit = mlog2(block_com_data_size(prev));
			blink_push(&pheap->buddy[bit], &b_prev->link);

			block_com_set_free(prev, true);
		}
	}
Ejemplo n.º 3
0
static void* heap_buddy_alloc_try(struct heap_buddy* pheap, int size) {
	int bit = 0;

	struct list_link *prop = NULL;
	struct heap_buddy_block *pb = NULL;

	for (bit = mlog2(size); bit < BUDDY_COUNT; bit ++) {
		prop = blink_find(&pheap->buddy[bit], size);

		if (prop != NULL)
			break;
	}

	if (prop == NULL) {
		/* we dont have enough space for this block */
		return NULL;
	}

	blink_pop(&pheap->buddy[bit], prop);

	{
		struct heap_buddy_block *pb = container_of(prop, struct heap_buddy_block, link);
		struct block_c *rem = NULL;

		/* When pb is deallocated, the data field should be used as list_link */
		if (size < sizeof(struct list_link)) 
			size = sizeof(struct list_link);

		/* Split the block, add the remain block to free container */
		rem = block_com_split(&pb->common, size, pheap->split_threshold);
		if (rem != NULL) {
			struct heap_buddy_block *rem_block = container_of(rem, struct heap_buddy_block, common);

			block_com_set_free(rem, true);

			bit = mlog2(block_com_data_size(rem));
			blink_push(&pheap->buddy[bit], &rem_block->link);
		}

		block_com_set_free(&pb->common, false);
		return block_com_data(&pb->common);
	}

	return NULL;
}
Ejemplo n.º 4
0
// ********************************************************************
// *
// *            mdlConstructCode
// *            ----------------
// *
// *     computes MDL code len for  construct 
// *
// *********************************************************************
double construct::mdlConstructCode() 
{
   double code = mlog2((double)no1bits(gFT->opt->constructionMode)) ;
   switch (compositionType)
   {
     case cSINGLEattribute:
          code += mlog2((double)gFT->noAttr) ;
          if (countType == aDISCRETE)
          {
//#if defined(DEBUG)
//            if ( ! leftValues.defined() )
//               merror("construct::mdlConstructCode", "unexpected form of a call") ;
//#endif
            marray<double> Multinom(2, 0.0) ;  
            for (int i=1 ; i < leftValues.len() ; i++)
              if (leftValues[i]) 
                Multinom[0] += 1.0 ;
            Multinom[1] = leftValues.len() - 1.0 - Multinom[0];
            Multinom.setFilled(2)  ;
            code += multinomLog2(Multinom) ;
          }
          else
          {
            double intValue = gFT->valueInterval[root->attrIdx]/gFT->opt->mdlModelPrecision ;
            if (intValue < 1.0)
              intValue = 1.0 ;
            code += mlog2(intValue) ;
          }
          break ;       
     case cCONJUNCTION:
     case cSUM:
     case cPRODUCT:
     case cXofN:
         code += mlog2((double)degreesOfFreedom()) ;
         code += mdlAux() ;       
         break ;
     default:
         merror("construct::mdlConstructCode","construct has unexpected composition") ;
   }
   return code ;
}
Ejemplo n.º 5
0
static void heap_buddy_expand_memory(struct heap_buddy* pheap, int expand_size) {
	struct block_c_pool* n_blk_pool = (struct block_c_pool*)
		alloc(pheap->__parent_alloc, pheap->__parent, sizeof(struct block_c_pool));

	void* n_mem_begin = 
		alloc(pheap->__parent_alloc, pheap->__parent, expand_size);

	dbg_assert(n_mem_begin != NULL);
	{
		/* initialize the new memory */
		struct block_c *sent_first = NULL;
		struct block_c *sent_last  = NULL;
		struct block_c *init_block = NULL;
		void* n_mem_end   = (void*)((char*)n_mem_begin + expand_size);

		init_block = block_com_make_sentinels(
				n_mem_begin, n_mem_end, &sent_first, &sent_last);
		block_com_set_free(init_block, true);

		n_blk_pool->memory = n_mem_begin;
		n_blk_pool->size   = expand_size;
		n_blk_pool->bc_first      = init_block;
		n_blk_pool->bc_front_sent = sent_first;
		n_blk_pool->bc_end_sent   = sent_last;
	}
	
	/* link the new memory into memory list */
	list_insert_back(&pheap->memlist, &n_blk_pool->link);

	/* insert the new block into the heap */
	{
		struct heap_buddy_block *n_block = 
			container_of(n_blk_pool->bc_first, struct heap_buddy_block, common);
		int sz = block_com_data_size(n_blk_pool->bc_first);

		blink_push(&pheap->buddy[mlog2(sz)], &n_block->link);
	}
}