Example #1
0
void bvh_done<SVBVHTree>(SVBVHTree *obj)
{
	rtbuild_done(obj->builder, &obj->rayobj.control);
	
	//TODO find a away to exactly calculate the needed memory
	MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE);
					   BLI_memarena_use_malloc(arena1);

	MemArena *arena2 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE);
					   BLI_memarena_use_malloc(arena2);
					   BLI_memarena_use_align(arena2, 16);

	//Build and optimize the tree
	if(0)
	{
		VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1,&obj->rayobj.control).transform(obj->builder);
		if(RE_rayobjectcontrol_test_break(&obj->rayobj.control))
		{
			BLI_memarena_free(arena1);
			BLI_memarena_free(arena2);
			return;
		}
		
		reorganize(root);
		remove_useless(root, &root);
		bvh_refit(root);
	
		pushup(root);
		pushdown(root);
		pushup_simd<VBVHNode,4>(root);
	
		obj->root = Reorganize_SVBVH<VBVHNode>(arena2).transform(root);
	}
	else
	{
		//Finds the optimal packing of this tree using a given cost model
		//TODO this uses quite a lot of memory, find ways to reduce memory usage during building
		OVBVHNode *root = BuildBinaryVBVH<OVBVHNode>(arena1,&obj->rayobj.control).transform(obj->builder);			
		if(RE_rayobjectcontrol_test_break(&obj->rayobj.control))
		{
			BLI_memarena_free(arena1);
			BLI_memarena_free(arena2);
			return;
		}

		VBVH_optimalPackSIMD<OVBVHNode,PackCost>(PackCost()).transform(root);
		obj->root = Reorganize_SVBVH<OVBVHNode>(arena2).transform(root);
	}

	
	//Free data
	BLI_memarena_free(arena1);
	
	obj->node_arena = arena2;
	obj->cost = 1.0;
	
	
	rtbuild_free( obj->builder );
	obj->builder = NULL;
}
Example #2
0
int
main(int argc, char *argv[]) {
    if (argc <= 1) {
        exit(1);
    }
    printf("result : %s\n", reorganize(argv[1]));
}
Example #3
0
 inline void BaseList<T>::prepare_size(size_type new_size)
 {
   // TODO overflow is not dealt with!
   if (new_size > m_capacity) {
     reorganize();
     adjust_capacity(new_size);
     // Size has to be adjusted afterwards in order to ensure that all old values are copied but not more than that.
   } else if (m_is_shrinkable && new_size < m_capacity / CAPACITY_DECREASE_FACTOR && new_size < m_size) {
     // Size has to be adjusted before because the later data is lost anyway and copying could cause a segfault because
     // there is not enough space in the new array. It is assumed that the content is deinitialized already.
     reorganize();
     m_size = new_size;
     adjust_capacity(new_size);
   }
   m_size = new_size;
 }
Example #4
0
//--------------------------------------------------------------
//  class WarpVolume member functions
//--------------------------------------------------------------
WarpVolume::WarpVolume(char* fVF, int xx, int yy, 
	float rx,float ry, float rz )
  :dimX(xx),dimY(yy),fdMap(NULL),
   voxSize(sizeof(struct Pt3d)), xres(rx), yres(ry), zres(rz)
{
   strcpy(fWarp, fVF);
   planSize = dimX*dimY;
   loadVolume(fVF, fdMap, dimZ);
   reorganize(fdMap,dimZ);
}
Example #5
0
int main(void) {

  if(!(disp = XOpenDisplay(0x0)))  {
    return 1;
  }

  root = DefaultRootWindow(disp);
  screen = DefaultScreen(disp);
  screen_width = DisplayWidth(disp, screen);
  screen_height = DisplayHeight(disp, screen);
  
  app_count = 0;

  XSetWindowAttributes windowAttr;
  windowAttr.event_mask = ExposureMask | StructureNotifyMask | SubstructureRedirectMask | SubstructureNotifyMask;
  XChangeWindowAttributes(disp, root, CWEventMask, &windowAttr);
  XSelectInput(disp, root, windowAttr.event_mask);

  /* Primary event loop */
  while (1) {
    XEvent ev;
    XNextEvent(disp, &ev);

    /* Event for a new app being added */
    if (ev.type == MapRequest) {
      
      XMapRequestEvent *req = &ev.xmaprequest;
      XMapWindow(disp, req->window);
      
      App *new_app; 
      new_app = calloc(1, sizeof(App));
      new_app->window = req->window;
      new_app->id = app_count;

      apps[app_count] = new_app;
      app_count++;
      reorganize();

    /* Event for an app being removed */
    } else if (ev.type == UnmapNotify) {
      XUnmapEvent *req = &ev.xunmap;
      App *remove_me = getApp(req->window);
      remove_me->id = -1;
    }
  }
}
Example #6
0
File: table.c Project: xuwenbo/KR
void
insertintodeltable(int *table, int *max, int size, int start)
{
    int i, j;
    
    //find the proper position
    for (i = *max; i >= 2; i -= 2)
    {
#ifdef ARY_VERSION
        if (table[i - 1] <= start)
#else
        if (*(table + i - 1) <= start)
#endif
        {
            break;
        }
    }
    
    //now we need to move some data foreward
    for (j = *max; j >= i + 2; j -= 2)
    {
#ifdef ARY_VERSION
        table[j + 1] = table[j - 1];
        table[j]     = table[j - 2];
#else
        *(table + j + 1) = *(table + j - 1);
        *(table + j)     = *(table + j - 2);
#endif
    }
    
    //now insert (size, start)
#ifdef  ARY_VERSION
    table[i]     = size;
    table[i + 1] = start;
#else
    *(table + i)     = size;
    *(table + i + 1) = start;
#endif
        
    *max += 2; 

    //reorganize
    reorganize(i);
}
Example #7
0
///////////////////////////////////
// and here the fun begins...
int
main (int argc, char *argv[])
{
  // option processing variables
  int  opt;
  int  option_index = 0;

  // should the action be forced
  bool forceAction = false;

  // should help be displayed
  bool displayHelp = false;

  // should version info be displayed
  bool displayVer = false;

  // the action the user has chosen to perform
  int  action = 0;

  // the argument to the action
  const char* action_arg = NULL;

  // should existing records be updated (default: No)
  bool updateRecords = false;

  // selected itemNr, 0 = no specific item selected
  uint16_t itemNr = 0;

  // enabled DBTypes (default to all)
  int dbTypes = (EQItemDB::LORE_DB | EQItemDB::NAME_DB | 
		 EQItemDB::DATA_DB | EQItemDB::RAW_DATA_DB);

  // search string
  QString search;

  // note program name for later use.
  progname = argv[0];

  // Get an instance of the EQItemDB
  EQItemDB* itemDB = new EQItemDB;
  
  // begin processing options
  while ((opt = getopt_long( argc,
			     argv,
			     OPTION_LIST,
			     option_list,
			     &option_index)) != -1)
    {
      switch(opt)
	{
	case 'd': // display an item
	case 'l': // list items
	case 'f': // import from a flat file db
	case 'r': // import from a itemrawdata.dbm file
	case 'o': // import from an old GDBM file
	case 'e': // export a raw data record
	case 'x': // export database as a CSV file
	case 'D': // delete a record
	case 'R': // reorganize database
	case 'u': // upgrade ItemDB to current format
	  // these actions are mutually exclusive, if two chosen, display help
	  if (action != 0)
	    displayHelp = true;
	  else
	  {
	    // save action and it's argument
	    action = opt;
	    action_arg = optarg;
	  }
	  break;
	case 'i':
	  itemNr = (uint16_t)atoi(optarg);
	  break;
	case 'U':
	  updateRecords = true;
	  break;
	case 'v':
	case 'V':
	  displayVer = true;
	  break;
	case ITEMDB_LORE_FILENAME_OPTION:
	  itemDB->SetDBFile(EQItemDB::LORE_DB, optarg);
	  break;
	case ITEMDB_NAME_FILENAME_OPTION:
	  itemDB->SetDBFile(EQItemDB::NAME_DB, optarg);
	  break;
	case ITEMDB_DATA_FILENAME_OPTION:
	  itemDB->SetDBFile(EQItemDB::DATA_DB, optarg);
	  break;
	case ITEMDB_RAW_FILENAME_OPTION:
	  itemDB->SetDBFile(EQItemDB::RAW_DATA_DB, optarg);
	  break;
	case ITEMDB_DATABASES_ENABLED:
	  dbTypes = atoi(optarg);
	  break;
	case FORCE_ACTION:
	  forceAction = true;
	  break;
	case 'h': // display usage info
	default:
	  displayHelp = true;
	  break;
	}
    }

  // if no action selected, display help
  if ((action == 0) && !displayHelp && !displayVer)
  {
    fprintf(stderr, "No action specified\n");
    displayHelp = true;
  }

  // are there extra arguments
  if (optind < argc)
  {
    //yes, there are

    // is the action list with no search argument
    if ((action == 'l') && (action_arg == 0))
    {
      // yes, so use them for the search argument
      while (optind < argc)
	{
	  if (!search.isEmpty())
	    search += " ";
	  
	  // append extra arguments to search string
	  search += argv[optind++];
	}
    }
    else // otherwise display help
    {
      fprintf(stderr, "Extra arguments!\n");
      displayHelp = true;
    }
  }

  // if either the display or delete actions were specified and no 
  // item was specified display help.
  if (((action == 'd') || (action == 'D')) && 
      (itemNr == 0))
    displayHelp = true;

  // result to return from the program (the exit code).
  int result = 0;

  // display the help/usage information if required and exit
  if (displayHelp)
  {
    // display the usage information
    displayUsage(); 

    // return non-zero result
    result = 1;
  }
  else
  {
    // enable the set of dbtypes
    itemDB->SetEnabledDBTypes(dbTypes);
    
    // display the version information
    if (displayVer)
      displayVersion(itemDB);

    // perform the requested action
    switch(action)
    {
    case 'd': // display an item
      result = displayRecord(itemDB, itemNr);
      break;
    case 'l': // list items
    {
      if (action_arg)
	search = action_arg;
      result = listRecords(itemDB, itemNr, search);
      break;
    }
    case 'f': // import from a flat file db
      result = importFlatFile(itemDB, action_arg, itemNr, 
			      forceAction, updateRecords);
      break;
    case 'r': // import from a itemrawdata.dbm file
    case 'o': // import from an old GDBM file
      // the above two options are really the same
      result = importGDBM(itemDB, action_arg, itemNr, 
			  forceAction, updateRecords);
      break;
    case 'e': // export a raw data record
      result = exportRawRecord(itemDB, action_arg, itemNr);
      break;
    case 'x': // export database as a CSV file
      result = exportRecordCSV(itemDB, action_arg, itemNr);
      break;
    case 'D': // delete a record
      result = deleteRecord(itemDB, itemNr, forceAction);
      break;
    case 'R': // reorganize database
      result = reorganize(itemDB);
      break;
    case 'u': // upgrade ItemDB to current format
      result = upgradeItemDB(itemDB);

    }
  }

  // shutdown the ItemDB
  itemDB->Shutdown();

  // delete this instance of ItemDB
  delete itemDB;

  return result;
}
Example #8
0
int insertR(int key, Node r_child_of_key, Node node, stack path_stack, int tid) {
    if (node->is_leaf) {
        // set the $thread_on bit to indicate thread $tid is entering. 
        pthread_mutex_lock(&node->mutex);
        node->thread_on |= 0x01 << tid;
        pthread_mutex_unlock(&node->mutex);

        while (node->reorganize_bit & 0x01) {
            //pthread_mutex_lock(&node->mutex); //can u get this lock???
            //pthread_cond_wait(&node->is_under_reorganizing, &node->mutex);
            //pthread_mutex_unlock(&node->mutex);
        }

        // check its own region capacity; not full is safe, and release locks 
        // of ancestors, including parent.
        if (node->private_region_capacity[tid] != 0) {
            while (!path_stack->is_empty(path_stack)) {
                pthread_mutex_unlock(&((Node) path_stack->top(path_stack)->data)->mutex);
                path_stack->pop(path_stack);
            }
        }

        // search in organized region (linear)
        int i;
        for (i = 0; i < node->organized_keys; ++i) {
            if (key == node->keys[i])
                return 0;
            else if (key < node->keys[i])
                break;
        }
        // key is between [i - 1] and [i]; follow child[i]

        // if it is leaf, linear search in private region (in leaf); or insert.

        // path_stack only contains from root to the parent of this $node.
        // insert the key record when $capacity != 0
        if (node->private_region_capacity[tid] != 0) {
            int insert_position = node->private_region_index[tid] + node->private_region_keys[tid];
            node->keys[insert_position] = key;
            //node->values[insert_position] = val;
            node->private_region_keys[tid] += 1;

            // if two threads meet the same situation and wait for each other to 
            // complete the reorganization... $reorganize_bit $thread_on??? 
            // how to deal with them in here. 
            if (node->private_region_capacity[tid] == node->private_region_keys[tid]) {
                pthread_mutex_lock(&node->mutex);
                if (!(node->reorganize_bit & 0x01) && 
                        (node->private_region_capacity[tid] == node->private_region_keys[tid]) && 
                        (node->private_region_capacity[tid] != 0)) {
                    node->reorganize_bit |= 0x01;
                    reorganize(node);
                    node->reorganize_bit &= 0x00;
                    //pthread_cond_broadcast(&node->is_under_reorganizing);
                }
                pthread_mutex_unlock(&node->mutex);
            }
        }
        else { // split the $node
            //TODO:
            // check whether other threads are manipulating the node by
            // using the $thread_on in each node. And wait to lock the node. 
            pthread_mutex_lock(&node->mutex);
            while (node->thread_on ^ (0x01 << tid)) {
                //!!!careful: if it needs to reset the $thread_on 
                // and set it after condition wait.
                node->thread_on ^= 0x01 << tid; //!? right or wrong?
                pthread_cond_wait(&node->is_going_splitting, &node->mutex);
                node->thread_on |= 0x01 << tid; //!? right or wrong?
            }
            // start to split; reorganize first
            node->reorganize_bit |= 0x01;
            reorganize(node);
            node->reorganize_bit &= 0x00;

            Node u = node;
            Node v = createNode(1); // 1 => is leaf;
            Node r_subtree = r_child_of_key;
            int median = splitLeaf(u, v);
            int elem = key;
            int finish = 0;
            if (u == root) {
                root = createNode(0);
                root->keys[0] = median;
                root->organized_keys++;
                root->child[0] = u;
                root->child[1] = v;
                finish = 1;
            }
            else {
                elem = median;
                r_subtree = v;
                u = (Node) path_stack->top(path_stack)->data;
                path_stack->pop(path_stack);
            }
            pthread_mutex_unlock(&node->mutex);

            while (/*!path_stack->is_empty() && */!finish) {
                if (u->organized_keys < (order - 1)) {
                    insertElem(elem, r_subtree, u);
                    finish = 1;
                }
                else {
                    v = createNode(0);
                    median = splitNonleaf(elem, r_subtree, u, v);

                    if (u == root) {
                        root = createNode(0);
                        root->keys[0] = median;
                        root->organized_keys++;
                        root->child[0] = u;
                        root->child[1] = v;
                        finish = 1;
                    }
                    else {
                        pthread_mutex_unlock(&u->mutex);
                        elem = median;
                        r_subtree = v;
                        u = (Node) path_stack->top(path_stack)->data;
                        path_stack->pop(path_stack);
                    }
                }
            }
            pthread_mutex_unlock(&u->mutex);
        }

        pthread_mutex_lock(&node->mutex);
        node->thread_on ^= 0x01 << tid;
        pthread_cond_signal(&node->is_going_splitting);
        pthread_mutex_unlock(&node->mutex);
    }
    else { // lock this node, and follow child[i]
        pthread_mutex_lock(&node->mutex);

        // if current node is safe, then release all ancestors.
        if (node->organized_keys < (order - 1)) {
            while (!path_stack->is_empty()) {
                pthread_mutex_unlock(&((Node) path_stack->top(path_stack)->data)->mutex);
                path_stack->pop(path_stack);
            }
        }

        // search in organized region (linear)
        int i;
        for (i = 0; i < node->organized_keys; ++i) {
            if (key == node->keys[i])
                return 0;
            else if (key < node->keys[i])
                break;
        }
        // key is between [i - 1] and [i]; follow child[i]

        struct stack_node_struct stack_node;
        stack_node.data = node;
        path_stack->push(path_stack, &stack_node);
        insertR(key, r_child_of_key, node->child[i], path_stack);
    }
}