コード例 #1
0
ファイル: mdd.cpp プロジェクト: eldarerathis/FDDL
node_idx Forest::InternalMax(level k, node_idx p, node_idx q)
{
    //Easy Terminal Cases
    if (p == 0 || p == q)
	return q;
    if (q == 0)
	return p;
    if (k == 0)
	return p > q ? p : q;

    //Check for an entry in the Cache.
    node_idx result;

    result = MaxCache[k]->hit(p, q);
    if (result >= 0) {
	if (!(FDDL_NODE(k, result).flags & FLAG_DELETED))
	    return result;
	if (garbage_alg != O_STRICT)
	    return CheckIn(k, result);
    }

    result = NewNode(k);	//result initially has size 0.
    Node *nodeP = &FDDL_NODE(k, p);
    Node *nodeQ = &FDDL_NODE(k, q);

    int psize = nodeP->size;
    int qsize = nodeQ->size;

    //If neither node is sparse, do things the easy way.
    if (!IS_SPARSE(nodeP) && !IS_SPARSE(nodeQ)) {
	for (arc_idx i = 0; i < (psize > qsize ? psize : qsize); i++) {
	    node_idx u = InternalMax(k - 1,
				     i < psize ? FULL_ARC(k, nodeP, i) : 0,
				     i < qsize ? FULL_ARC(k, nodeQ,
							  i) : 0);

	    SetArc(k, result, i, u);
	}
    } else if (IS_SPARSE(nodeP) && IS_SPARSE(nodeQ)) {
	//If both nodes are sparse, do things the fast way!
	//Scan from left to right.  If i is the smaller value, put it in the
	//node.  If j is the smaller value, put it in the node.  If i==j, put
	//the union of i and j in the node.  

	for (arc_idx i = 0, j = 0; i < psize || j < qsize;) {
	    arc_idx pdx = SPARSE_INDEX(k, nodeP, i);
	    node_idx pval = SPARSE_ARC(k, nodeP, i);
	    arc_idx qdx = SPARSE_INDEX(k, nodeQ, j);
	    node_idx qval = SPARSE_ARC(k, nodeQ, j);

	    if (i >= psize) {
		SetArc(k, result, qdx, qval);
		j++;
	    } else if (j >= qsize) {
		SetArc(k, result, pdx, pval);
		i++;
	    } else if (pdx < qdx) {
		SetArc(k, result, pdx, pval);
		i++;
	    } else if (qdx < pdx) {
		SetArc(k, result, qdx, qval);
		j++;
	    } else {
		SetArc(k, result, pdx, InternalMax(k - 1, pval, qval));
		i++;
		j++;
	    }
	}
    } else {
	if (IS_SPARSE(nodeP) && !IS_SPARSE(nodeQ)) {
	    int j = 0;

	    for (int i = 0; i < nodeP->size || j < nodeQ->size;) {
		int idx = SPARSE_INDEX(k, nodeP, i);
		int ival = SPARSE_ARC(k, nodeP, i);
		int jval = FULL_ARC(k, nodeQ, j);

		if (i >= nodeP->size) {
		    SetArc(k, result, j, jval);
		    j++;
		} else if (j >= nodeQ->size) {
		    SetArc(k, result, idx, ival);
		    i++;
		} else if (j < idx) {
		    SetArc(k, result, j, jval);
		    j++;
		} else if (idx < j) {
		    SetArc(k, result, idx, ival);
		    i++;
		} else {
		    SetArc(k, result, j, InternalMax(k - 1, ival, jval));
		    i++;
		    j++;
		}
	    }
	} else if (IS_SPARSE(nodeQ) && !IS_SPARSE(nodeP)) {
	    int j = 0;

	    for (int i = 0; i < nodeP->size || j < nodeQ->size;) {
		int jdx = SPARSE_INDEX(k, nodeQ, j);
		int jval = SPARSE_ARC(k, nodeQ, j);
		int ival = FULL_ARC(k, nodeP, i);

		if (i >= nodeP->size) {
		    SetArc(k, result, jdx, jval);
		    j++;
		} else if (j >= nodeQ->size) {
		    SetArc(k, result, i, ival);
		    i++;
		} else if (i < jdx) {
		    SetArc(k, result, i, ival);
		    i++;
		} else if (jdx < i) {
		    SetArc(k, result, jdx, jval);
		    j++;
		} else {
		    SetArc(k, result, i, InternalMax(k - 1, ival, jval));
		    i++;
		    j++;
		}
	    }

	}
    }

    node_idx newresult = CheckIn(k, result);

//  if (k > 0 && newresult)
//    FDDL_NODE (k, newresult).flags |= FLAG_CHECKED_IN;
    MaxCache[k]->add(newresult, p, q);
    MaxCache[k]->add(newresult, q, p);
    MaxCache[k]->add(newresult, p, newresult);
    MaxCache[k]->add(newresult, q, newresult);
    return newresult;
}
コード例 #2
0
bool ofxCrazyradio::init() {
  int ret = libusb_init(&ctx_);
//  std::cout << "libusb_init: " << ret << std::endl;
//  libusb_set_debug(ctx_, 3);
  
  bool found = false;
  libusb_device **list;
  ssize_t count = libusb_get_device_list(ctx_, &list);
//  std::cout << "libusb_get_device_list: " << count << std::endl;
  for (int i = 0; i < count; i++) {
    struct libusb_device_descriptor desc;
    ret = libusb_get_device_descriptor(list[i], &desc);
    if (desc.idVendor == 0x1915 && desc.idProduct == 0x7777) {
      found = true;
      ret = libusb_open(list[i], &handle_);
//      std::cout << "libusb_open: " << ret << std::endl;
      
//      std::cout << "version: " << std::hex << desc.bcdDevice << std::dec << std::endl;
      
//      uint8_t string_desc[256];
//      ret = libusb_get_string_descriptor_ascii(handle_, desc.iManufacturer, string_desc, 256);
//      std::cout << "libusb_get_string_descriptor_ascii: " << ret << std::endl;
//      std::cout << string_desc << std::endl;
//
      
//      for (int n = 0; n < desc.bNumConfigurations; n++) {
//        libusb_config_descriptor *config_desc;
//        const libusb_interface_descriptor *inter_desc;
//        const libusb_endpoint_descriptor *ep_desc;
//        const libusb_interface *inter;
//        libusb_get_config_descriptor(list[i], n, &config_desc);
//        std::cout << "config: " << (int)config_desc->bConfigurationValue << std::endl;
//        std::cout << "bNumInterfaces: " << (int)config_desc->bNumInterfaces << std::endl;
//        for (int i = 0; i < (int)config_desc->bNumInterfaces; i++) {
//          inter = &config_desc->interface[i];
//          std::cout << "  num_altsetting: " << inter->num_altsetting << std::endl;
//          for (int j = 0; j < inter->num_altsetting; j++) {
//            inter_desc = &inter->altsetting[j];
//            std::cout << "    Interface number: " << (int)inter_desc->bInterfaceNumber << std::endl;
//            std::cout << "    number of endpoint: " << (int)inter_desc->bNumEndpoints << std::endl;
//            for (int k = 0; k < (int)inter_desc->bNumEndpoints; k++) {
//              ep_desc = &inter_desc->endpoint[k];
//              std::cout << "     desc type: " << (int)ep_desc->bDescriptorType << std::endl;
//              std::cout << "     ep address: " << (int)ep_desc->bEndpointAddress << std::endl;
//              std::cout << "     attributes: " << std::hex << (int)ep_desc->bmAttributes << std::dec << std::endl;
//            }
//          }
//        }
//      }
      
//      ret = libusb_kernel_driver_active(handle_, 0);
//      std::cout << "libusb_kernel_driver_active: " << ret << std::endl;
      
      ret = libusb_claim_interface(handle_, 0);
//      std::cout << "libusb_claim_interface: " << ret << std::endl;
      
      libusb_set_configuration(handle_, 1);
      SetDataRate(DR_250KPS);
      SetChannel(2);
      arc_ = -1;
      SetContCarrier(false);
      uint8_t address[] = "\xe7\xe7\xe7\xe7\xe7";
      SetAddress(address);
      SetPower(P_0DBM);
      SetArc(3);
      SetArdBytes(32);
      break;
    }
  }
  libusb_free_device_list(list, 1);
  
  return found;
}