static inline void
list_remove_item(struct list* list, void* item)
{
	list_link* link = GET_LINK(list, item);

	link->next->prev = link->prev;
	link->prev->next = link->next;
}
Esempio n. 2
0
ehgraph_t* permute_graph(ehgraph_t* graph, int* perm) {
  ehgraph_t* ret = NULL, *b = NULL;

  do {
    CheckNotNULL(graph);
    CheckNotNULL(perm);

    if (0 != perm[0]) {
      DB_ERROR("the null element should remain unchanged in the permutation");
      break;
    }
    
    b = ehgraph_alloc(NULL, graph->size, graph->ptrdim, graph->nLinks);
    if (!b) {
      DB_ERROR("allocation failed");
      break;
    }

    b->closed = graph->closed;

    for (enode_t i = 0; i < graph->ptrdim; ++i) 
      VAR2NODE(b, i) = perm[ VAR2NODE(graph, i) ];

    for (enode_t i = 0; i < graph->size; ++i) {
      GET_NODE(b, perm[i]).inDoubleLink = GET_NODE(graph, i).inDoubleLink;
      GET_NODE(b, perm[i]).outDoubleLink = GET_NODE(graph, i).outDoubleLink;

      for (size_t l = 0; l < graph->nLinks; ++l) {
	GET_LINK(b, perm[i], l) = perm[ GET_LINK(graph, i, l) ];
	GET_NODE(b, perm[i]).superEdge[l] = GET_NODE(graph, i).superEdge[l];

	for (size_t lp = 0; lp < graph->nLinks; ++lp) {
	  GET_NODE(b, perm[i]).isPredicate[l][lp] = GET_NODE(graph, i).isPredicate[l][lp];
	  GET_NODE(b, perm[i]).predicateTarget[l][lp] = perm[ GET_NODE(graph, i).predicateTarget[l][lp] ];
	}
      }
    }
	   
    ret = b;
  } while(0);
  
  if (!ret)
    SafeFree(b);
  
  return ret;
}
static inline void
list_add_item(struct list* list, void* item)
{
	list_link* link = GET_LINK(list, item);

	link->next = &list->link;
	link->prev = list->link.prev;

	list->link.prev->next = link;
	list->link.prev = link;
}
static inline void*
list_get_next_item(struct list* list, void* item)
{
	if (item == NULL) {
		if (list->link.next == (list_link *)list)
			return NULL;

		return GET_ITEM(list, list->link.next);
	}

	list_link* link = GET_LINK(list, item);
	if (link->next == &list->link)
		return NULL;

	return GET_ITEM(list, link->next);
}
Esempio n. 5
0
static walk_result WlkClear( imp_image_handle *ii, imp_mod_handle im, void *d )
{
    unsigned            dmnd;
    mod_info            *mp;
    section_info        *sect;
    int                 entry;
    unsigned            real_entry;
    pointer_int         *lnk;

    d = d;
    mp = ModPointer( ii, im );
    sect = FindInfo( ii, im );
    for( dmnd = DMND_FIRST; dmnd < DMND_NUM; ++dmnd ) {
        for( entry = mp->di[dmnd].u.entries-1; entry >= 0; --entry ) {
            real_entry = entry + mp->di[dmnd].info_off;
            lnk = &GET_LINK( sect, real_entry );
            if( IS_RESIDENT( *lnk ) ) {
                Unload( MK_DMND_PTR( *lnk ) );
            }
        }
    }
    return( WR_CONTINUE );
}
Esempio n. 6
0
void *InfoLoad( imp_image_handle *ii, imp_mod_handle im, unsigned item,
                unsigned entry, void (*clear)(void *, void *) )
{
    demand_ctrl         *section;
    demand_info         *info;
    section_info        *sect;
    unsigned long       tmpoff;
    pointer_int         *lnk;
    unsigned            size;

    ++TimeStamp;
    if( TimeStamp == 0 ) { /* TimeStamp wrapped */
        TimeStamp = 1;
        for(section = DemandList; section != NULL; section = section->link) {
            section->time_stamp = 0;
        }
    }
    info = &ModPointer( ii, im )->di[ item ];
    if( entry >= info->u.entries )
        return( NULL );
    entry += info->info_off;
    sect = FindInfo( ii, im );
    lnk = &GET_LINK( sect, entry );
    if( IS_RESIDENT( *lnk ) ) {
        section = MK_DMND_PTR( *lnk );
    } else {
        /* section not loaded */
        size = DMND_SIZE( sect, entry );
        if( (LastDemand->owner == NULL || LastDemand->size < size)
            && LastDemand->locks == 0 ) {
            /* keep largest section in LastDemand */
            section = LastDemand;
            Unload( LastDemand );
        } else {
            /* allocate some memory */
            section = DCAlloc( _demand_size( size ) );
            if( section == NULL ) {
                if( LastDemand->locks != 0 )
                    return( NULL );
                /* no memory, use last chance */
                section = LastDemand;
                Unload( LastDemand );
            }
        }
        tmpoff = MK_DMND_OFFSET( *lnk );
        if( InfoRead( sect, tmpoff, size, section->buff ) != DS_OK ) {
            if( section != LastDemand )
                DCFree( section );
            return( NULL );
        }
        section->size = size;
        section->locks = 0;
        section->clear = clear;
        section->owner = lnk;
        section->save  = *lnk;
        *lnk = STASH_DMND_PTR( section );
        if( section != LastDemand ) {
            section->link = DemandList;
            DemandList = section;
        }
    }
    section->time_stamp = TimeStamp; /* for removal priority */
    section->locks++;
    return( section->buff );
}