Example #1
0
FilterDataPtr TransformFilter::apply(FilterDataPtr input) {
    // To apply the transform, we just add a new node and put all root nodes as
    // children of it.

    for(FilterData::const_iterator md_it = input->begin(); md_it != input->end(); md_it++) {
        VisualPtr vis = *md_it;
        MeshdataPtr md( std::tr1::dynamic_pointer_cast<Meshdata>(vis) );

        if (!md) {
            SILOG(transform-filter, warning, "Can't transform this type of visual: " << vis->type());
            continue;
        }

        Node new_root(NullNodeIndex, mTransform);
        new_root.children = md->rootNodes;

        NodeIndex new_root_index = md->nodes.size();
        md->nodes.push_back(new_root);

        md->rootNodes.clear();
        md->rootNodes.push_back(new_root_index);
    }

    return input;
}
Example #2
0
BNode<T>& BManager<T>::get_root() {
  if (num_nodes == 0) {
    BNode<T>& root = new_root();
    first_leaf_id = root.id;
    return root;
  }
  return get_node(root_node_id);
}
Example #3
0
    inline void split(Node & n) const
    {
        typedef rtree::split<Value, Options, Translator, Box, Allocators, typename Options::split_tag> split_algo;

        typename split_algo::nodes_container_type additional_nodes;
        Box n_box;

        split_algo::apply(additional_nodes, n, n_box, m_parameters, m_translator, m_allocators);                // MAY THROW (V, E: alloc, copy, N:alloc)

        BOOST_GEOMETRY_INDEX_ASSERT(additional_nodes.size() == 1, "unexpected number of additional nodes");

        // TODO add all additional nodes
        // For kmeans algorithm:
        // elements number may be greater than node max elements count
        // split and reinsert must take node with some elements count
        // and container of additional elements (std::pair<Box, node*>s or Values)
        // and translator + allocators
        // where node_elements_count + additional_elements > node_max_elements_count
        // What with elements other than std::pair<Box, node*> ?
        // Implement template <node_tag> struct node_element_type or something like that

        // for exception safety
        node_auto_ptr additional_node_ptr(additional_nodes[0].second, m_allocators);

        // node is not the root - just add the new node
        if ( !m_traverse_data.current_is_root() )
        {
            // update old node's box
            m_traverse_data.current_element().first = n_box;
            // add new node to parent's children
            m_traverse_data.parent_elements().push_back(additional_nodes[0]);                                     // MAY THROW, STRONG (V, E: alloc, copy)
        }
        // node is the root - add level
        else
        {
            BOOST_GEOMETRY_INDEX_ASSERT(&n == &rtree::get<Node>(*m_root_node), "node should be the root");

            // create new root and add nodes
            node_auto_ptr new_root(rtree::create_node<Allocators, internal_node>::apply(m_allocators), m_allocators); // MAY THROW, STRONG (N:alloc)

            BOOST_TRY
            {
                rtree::elements(rtree::get<internal_node>(*new_root)).push_back(rtree::make_ptr_pair(n_box, m_root_node));  // MAY THROW, STRONG (E:alloc, copy)
                rtree::elements(rtree::get<internal_node>(*new_root)).push_back(additional_nodes[0]);                 // MAY THROW, STRONG (E:alloc, copy)
            }
            BOOST_CATCH(...)
            {
                // clear new root to not delete in the ~node_auto_ptr() potentially stored old root node
                rtree::elements(rtree::get<internal_node>(*new_root)).clear();
                BOOST_RETHROW                                                                                           // RETHROW
            }
            BOOST_CATCH_END

            m_root_node = new_root.get();
            ++m_leafs_level;

            new_root.release();
        }
Example #4
0
	void bin_index_t::file_node::add_item(const index_t& val)
	{
		if(root_page->items_count()<root_page->page_max)
		{
			add_item(val,*root_page);
			return;
		}

		page_ptr new_root(create_page());
		index_ref r=(*new_root)[0];
		r.left()=root_page->page_offset;

		add_item(val,*new_root);

		root_page=new_root;
		append_page(*new_root);
		add_page(root_page);

		save_index_data(0,new_root->page_offset);
	}
Example #5
0
pcap_handler analyze_packets(unsigned char *p, struct pcap_pkthdr *h, unsigned char *packet)
{
  /*
    Assumption:  We are only worried about Ethernet
    Process:  Grab the packet headers, identify protocol
              and attach pointers to the headers.  Key the
	      packets using a hash of the IP port pairs.
	      Build a tree according to packet contents.
	      Nodes will hold value and count.  Top level
	      counts can be used to deduce frequency.
  */

  unsigned char *ip_header, *saddr, *daddr, *checksum, *chkptr, *data;
  unsigned int ip_words[64];
  unsigned int i, header_length, num_words, chksum;
  unsigned char chkflag;
  unsigned int hash_value;
  struct root_struct *ptr;

  packets++;
  DEBUG("Handling packet");
  ip_header = (packet + 14);
  header_length = get_header_length(ip_header);
  switch(ip_header[9])
    {
    case 0x01 : //ICMP
      data = ip_header + header_length + 4;
      break;
    case 0x06 : //TCP
      data = ip_header + header_length + 20;
      break;
    case 0x11: //UDP
      data = ip_header + header_length + 8;
      break;
    case 0x32: //ESP
      data = ip_header + header_length + 8;
      break;
    case 0x02: //IGMP
      data = ip_header + header_length + 8;
      break;
    default : 
      if(!(flags & QUIET))
	printf("\tUnknown: %x\n", (unsigned char)ip_header[9] );
      data = ip_header + header_length;
      break;
    }
  data = (flags & SRC_PORTS ? ip_header + header_length :
	  (flags & DST_PORTS ? ip_header + header_length + 2 :
	   (flags & IPIDS ? ip_header + 4 :
	    (flags & SEQ_NUMS ? ip_header + header_length + 4 :
	     (flags & SRC_HOSTS ? ip_header + 12 :
        (flags & CHECKSUM ? ip_header + 10 :
	     data))))));
  if((data + significant_bytes) > 
     (ip_header + ntohs(*((unsigned short int *)ip_header+1))))
    {
      if(!(flags & QUIET)) printf("Not enough data!\n");
      return 0;
    }
  ptr = find_root(data, root);
  DEBUG("Root found");
  if(ptr == NULL)
    {
      DEBUG("New root needed");
      ptr = new_root();
      DEBUG("New root allocated");
      sigs++;
      memcpy(ptr->key, data, significant_bytes);
      DEBUG("Completed memcpy");
      hash_value = hash(data);
      ptr -> hash_value = hash_value;
      if(root == NULL)
	{ 
	  hash_table[hash_value] = ptr;
	  root = ptr;
	  last = root;
	}
      else 
	{
	  insert(ptr);
	}
    }
  ptr->count ++;
  bzero(data, significant_bytes + 1);
}