void CompoundVector::ScalImpl(Number alpha)
 {
   DBG_START_METH("CompoundVector::ScalImpl", dbg_verbosity);
   DBG_ASSERT(vectors_valid_);
   for (Index i=0; i<NComps(); i++) {
     DBG_ASSERT(Comp(i));
     Comp(i)->Scal(alpha);
   }
 }
  void CompoundVector::AxpyImpl(Number alpha, const Vector &x)
  {
    DBG_START_METH("CompoundVector::AxpyImpl", dbg_verbosity);
    DBG_ASSERT(vectors_valid_);
    const CompoundVector* comp_x = static_cast<const CompoundVector*>(&x);
    DBG_ASSERT(dynamic_cast<const CompoundVector*>(&x));

    DBG_ASSERT(NComps() == comp_x->NComps());
    for (Index i=0; i<NComps(); i++) {
      DBG_ASSERT(Comp(i));
      Comp(i)->Axpy(alpha, *comp_x->GetComp(i));
    }
  }
Ejemplo n.º 3
0
 void siftDown(int pos) {
   while (2*pos+1 < num_) {//!isLeaf(pos) ) {
     int l = leftChild(pos);
     int r = l + 1;
     if (r < num_ && Comp()(heap_[r], heap_[l]) ) {
       l = r;
     }
     if (Comp()(heap_[l], heap_[pos]) ) {
         std::swap(heap_[pos], heap_[l]);
     }
     pos = l;
   }
 }
Ejemplo n.º 4
0
int Q_Find( queue *q, void *data, int(*Comp)( const void *, const void * ) )
{
    void *d;
    d = Q_First( q );
    do
    {
        if ( Comp( d, data ) == 0 ) return True_;
        d = Q_Next( q );
    }
    while ( !Q_End( q ) );

    if ( Comp( d, data ) == 0 ) return True_;

    return False_;
}
Ejemplo n.º 5
0
 Node<Key, Val>* DeleteInternal(Node<Key, Val>* h, Key key){
   if (h == NULL) return NULL;
   if (Comp()(key, h->key)){
     if (!IsRED(h->left) && 
         h->left != NULL &&
         !IsRED(h->left->left)){
       h = MoveREDLeft(h);
     }
     h->left = DeleteInternal(h->left, key);
   } else {
     if (IsRED(h->left)){
       h = RotateRight(h);
     }
     if ((key == h->key) && (h->right == NULL)){
       return NULL;
     }
     if (!IsRED(h->right) && 
         h->right != NULL && 
         !IsRED(h->right->left)){
       h = MoveREDRight(h);
     }
     if (key == h->key){
       Node<Key, Val>* min_node = GetMin(h->right);
       h->key = min_node->key;
       h->val = min_node->val;
       h->right = DeleteMin(h->right);
     } else {
       h->right = DeleteInternal(h->right, key);
     }
   }
   return FixUp(h);
 }
Ejemplo n.º 6
0
  Node<Key, Val>* InsertInternal(Node<Key, Val>* h, Key key, Val val){
    if (h == NULL){
      ++num_;
      return new Node<Key, Val>(key, val);
    }
    
    if (IsRED(h->left) && IsRED(h->right)){
      FlipColor(h);
    }

    if (key == h->key){
      h->val = val;
    } else if (Comp()(key, h->key)){
      h->left = InsertInternal(h->left, key, val);
    } else {
      h->right = InsertInternal(h->right, key, val);
    }
    
    if (IsRED(h->right)){
      h = RotateLeft(h);
    }

    if (IsRED(h->left) && IsRED(h->left->left)){
      h = RotateRight(h);
    }

    return h;
  }
Ejemplo n.º 7
0
CAComponent::CAComponent (OSType inType, OSType inSubtype, OSType inManu)
	: mDesc (inType, inSubtype, inManu),
	  mManuName(0), mAUName(0), mCompName(0)
{
	mComp = AudioComponentFindNext (NULL, &mDesc);
	AudioComponentGetDescription (Comp(), &mDesc);
}
	/**
	 * @param connections given a list of connections include two cities and cost
	 * @return a list of connections from results
	 */
	vector<Connection> lowestCost(vector<Connection>& connections) {
		sort(connections.begin(), connections.end(), Comp());
		unordered_map<string, int> labels;
		int n = 0;
		for (const auto & i : connections) {
			if (!labels.count(i.city1)) {
				labels[i.city1] = n;
				++n;
			}
			if (!labels.count(i.city2)) {
				labels[i.city2] = n;
				++n;
			}
		}
		vector<int> roots(n);
		iota(roots.begin(), roots.end(), 0);
		vector<Connection> result;
		for (const auto & i : connections) {
			int label1 = labels[i.city1], label2 = labels[i.city2];
			int root1 = getRoot(roots, label1), root2 = getRoot(roots, label2);
			if (root1 != root2) {
				roots[root1] = root2;
				--n;
				result.push_back(i);
			}
		}
		return n == 1 ? result : vector<Connection>();
	}
Ejemplo n.º 9
0
CAComponent::CAComponent (OSType inType, OSType inSubtype, OSType inManu)
	: mDesc (inType, inSubtype, inManu),
	  mManuName(0), mAUName(0), mCompName(0), mCompInfo (0)
{
	mComp = FindNextComponent (NULL, &mDesc);
	GetComponentInfo (Comp(), &mDesc, NULL, NULL, NULL);
}
Ejemplo n.º 10
0
int
CA_STEP3_check_pcd_pubkey(const EAC_CTX *ctx,
        const BUF_MEM *comp_pubkey, const BUF_MEM *pubkey)
{
    BUF_MEM *my_comp_pubkey = NULL;
    int r = -1;

    check((ctx && ctx->ca_ctx && comp_pubkey && ctx->ca_ctx->ka_ctx),
           "Invalid arguments");

    /* Compress own public key */
    my_comp_pubkey = Comp(ctx->ca_ctx->ka_ctx->key, pubkey, ctx->bn_ctx, ctx->md_ctx);
    check(my_comp_pubkey, "Failed to compress public key");

    /* Check whether or not the received data fits the own data */
    if (my_comp_pubkey->length != comp_pubkey->length
            || memcmp(my_comp_pubkey->data, comp_pubkey->data, comp_pubkey->length) != 0) {
        log_err("Wrong public key");
        r = 0;
    } else
        r = 1;

err:
    if (my_comp_pubkey)
        BUF_MEM_free(my_comp_pubkey);

    return r;
}
Ejemplo n.º 11
0
void 		CAComponent::SetCompNames () const
{
	if (!mCompName) {
	
		CFStringRef compName;
		OSStatus result = AudioComponentCopyName (Comp(), &compName);
		if (result) return;
		
		const_cast<CAComponent*>(this)->mCompName = compName;
		if (compName)
		{
			CFArrayRef splitStrArray = CFStringCreateArrayBySeparatingStrings(NULL, compName, CFSTR(":"));
			
			// we need to retain these values so the strings are not lost when the array is released
			const_cast<CAComponent*>(this)->mManuName = (CFStringRef)CFArrayGetValueAtIndex(splitStrArray, 0);
            CFRetain(this->mManuName);
			if (CFArrayGetCount(splitStrArray) > 1)
			{
				CFStringRef str = (CFStringRef)CFArrayGetValueAtIndex(splitStrArray, 1);
				
				CFMutableStringRef mstr = CFStringCreateMutableCopy (NULL, CFStringGetLength(str), str);

				// this needs to trim out white space:
				
				CFStringTrimWhitespace (mstr);
			
				const_cast<CAComponent*>(this)->mAUName = mstr;
			} else
				const_cast<CAComponent*>(this)->mAUName = NULL;
			
			CFRelease(splitStrArray);
		}
	}
}
Ejemplo n.º 12
0
double auc(const dvec_t& dec_values, const ivec_t& ty){
	double roc  = 0;
	size_t size = dec_values.size();
	size_t i;
	std::vector<size_t> indices(size);

	for(i = 0; i < size; ++i) indices[i] = i;

	std::sort(indices.begin(), indices.end(), Comp(&dec_values[0]));

	int tp = 0,fp = 0;
	for(i = 0; i < size; i++) {
		if(ty[indices[i]] == 1) tp++;
		else if(ty[indices[i]] == -1) {
			roc += tp;
			fp++;
		}
	}

	if(tp == 0 || fp == 0)
	{
		fprintf(stderr, "warning: Too few postive true labels or negative true labels\n");
		roc = 0;
	}
	else
		roc = roc / tp / fp;

	printf("AUC = %g\n", roc);

	return roc;
}
Ejemplo n.º 13
0
void		CAAudioUnit::Print (FILE* file) const
{
	fprintf (file, "AudioUnit:%p\n", AU());
	if (IsValid()) {
		fprintf (file, "\tnode=%ld\t", (long)GetAUNode()); Comp().Print (file);
	}
}
Ejemplo n.º 14
0
static int Q_BSearch( queue *q, void *key,
                      int (*Comp)(const void *, const void*))
{
      int low, mid, hi, val;

      low = 0;
      hi = q->size - 1;

      while (low <= hi)
      {
            mid = (low + hi) / 2;
            val = Comp(key, Q_index[ mid ]);

            if (val < 0)
                  hi = mid - 1;

            else if (val > 0)
                  low = mid + 1;

            else /* Success */
                  return mid;
      }

      /* Not Found */

      return -1;
}
 void CompoundVector::SetImpl(Number value)
 {
   DBG_START_METH("CompoundVector::SetImpl", dbg_verbosity);
   DBG_ASSERT(vectors_valid_);
   for (Index i=0; i<NComps(); i++) {
     Comp(i)->Set(value);
   }
 }
Ejemplo n.º 16
0
 /** Non const version of GetComp.
  *
  *  You should only use this method
  *  if you are intending to change the matrix you receive, since
  *  this CompoundSymMatrix will be marked as changed.
  */
 SmartPtr<Matrix> GetCompNonConst(
    Index irow,
    Index jcol
    )
 {
    ObjectChanged();
    return Comp(irow, jcol);
 }
Ejemplo n.º 17
0
 void bubble_sort(const Iterator& first, const Iterator& last, const Comp& comp = Comp()) {
     if(first == last) return;
     for(Iterator it = first; it != last - 1; ++it) {
         for(Iterator forward_it = last - 1; forward_it != it; --forward_it) {
             if(comp(*forward_it, *(forward_it - 1))) std::swap(*forward_it, *(forward_it-1));
         }
     }
 };
Ejemplo n.º 18
0
CAComponent::CAComponent (const AudioComponent& comp) 
	: mComp (comp),
	  mManuName(0), 
	  mAUName(0), 
	  mCompName(0)
{
	AudioComponentGetDescription (Comp(), &mDesc);
}
 void CompoundVector::ElementWiseSgnImpl()
 {
   DBG_START_METH("CompoundVector::ElementWiseSgnImpl", dbg_verbosity);
   DBG_ASSERT(vectors_valid_);
   for (Index i=0; i<NComps(); i++) {
     Comp(i)->ElementWiseSgn();
   }
 }
 void CompoundVector::AddScalarImpl(Number scalar)
 {
   DBG_START_METH("CompoundVector::AddScalarImpl", dbg_verbosity);
   DBG_ASSERT(vectors_valid_);
   for (Index i=0; i<NComps(); i++) {
     Comp(i)->AddScalar(scalar);
   }
 }
Ejemplo n.º 21
0
CAComponent::CAComponent (const AudioComponentInstance& compInst) 
	: mComp (NULL), 
	  mManuName(0), 
	  mAUName(0), 
	  mCompName(0)
{ 
	mComp = AudioComponentInstanceGetComponent (compInst);
	AudioComponentGetDescription (Comp(), &mDesc);
}
Ejemplo n.º 22
0
CAComponent::CAComponent (const AudioComponentDescription& inDesc, CAComponent* next)
	: mManuName(0), mAUName(0), mCompName(0)
{
	mComp = AudioComponentFindNext ((next ? next->Comp() : NULL), &inDesc);
	if (mComp)
		AudioComponentGetDescription(Comp(), &mDesc);
	else
		memcpy (&mDesc, &inDesc, sizeof(AudioComponentDescription));
}
Ejemplo n.º 23
0
CAComponent::CAComponent (const ComponentInstance& compInst) 
	: mComp (Component(compInst)), 
	  mManuName(0), 
	  mAUName(0), 
	  mCompName(0), 
	  mCompInfo (0) 
{ 
	GetComponentInfo (Comp(), &mDesc, NULL, NULL, NULL);
}
Ejemplo n.º 24
0
CAComponent::CAComponent (const ComponentDescription& inDesc, CAComponent* next)
	: mManuName(0), mAUName(0), mCompName(0), mCompInfo (0)
{
	mComp = FindNextComponent ((next ? next->Comp() : NULL), const_cast<ComponentDescription*>(&inDesc));
	if (mComp)
		GetComponentInfo (Comp(), &mDesc, NULL, NULL, NULL);
	else
		memcpy (&mDesc, &inDesc, sizeof(ComponentDescription));
}
Ejemplo n.º 25
0
void	CAComponent::Print(FILE* file) const
{
	fprintf (file, "CAComponent: %p", Comp());
	if (mManuName) {
		fprintf (file, ", Manu:"); _ShowCF (file, mManuName);
		if (mAUName) fprintf (file, ", Name:"); _ShowCF (file, mAUName);
	}
	fprintf (file, ", "); 
	Desc ().Print(file);
}
Ejemplo n.º 26
0
 void pushElem(const Elem& e) {
   assert(num_ < maxN && "heap is full");
   int curr = num_++;
   heap_[curr] = e;
   while (curr != 0 &&
       Comp()(heap_[curr], heap_(parent(curr) ) )  ){
     std::swap(heap_[curr], heap_[parent(curr)]);
     curr = parent(curr);
   }
 }
Ejemplo n.º 27
0
 void select_sort(const Iterator &first, const Iterator &last, const Comp &comp = Comp()) {
     if (first == last) return;
     for (Iterator it = first; it != last - 1; ++it) {
         Iterator minIt = it;
         for (Iterator backward_it = it + 1; backward_it != last; ++backward_it) {
             if (comp(*backward_it, *minIt)) minIt = backward_it;
         }
         if (minIt != it) std::swap(*it, *minIt);
     }
 };
Ejemplo n.º 28
0
Archivo: main.cpp Proyecto: CCJY/coliru
int main()
{
    // note: not ordered, only partitioned w.r.t. S defined below
    std::vector<S> vec = { {1,'A'}, {2,'B'}, {2,'C'}, {2,'D'}, {4,'G'}, {3,'F'} };
 
    auto p = std::equal_range(vec.begin(),vec.end(),2,Comp());
 
    for ( auto i = p.first; i != p.second; ++i )
        std::cout << i->name << ' ';
}
Ejemplo n.º 29
0
bool		CAAudioUnit::SupportsNumChannels () const
{
	// this is the default assumption of an audio effect unit
	Boolean* isWritable = 0;
	UInt32	dataSize = 0;
		// lets see if the unit has any channel restrictions
	OSStatus result = AudioUnitGetPropertyInfo (AU(),
									kAudioUnitProperty_SupportedNumChannels,
									kAudioUnitScope_Global, 0,
									&dataSize, isWritable); //don't care if this is writable

		// if this property is NOT implemented an FX unit
		// is expected to deal with same channel valance in and out
	if (result) {
		if (Comp().Desc().IsEffect() || Comp().Desc().IsOffline())
			return true;
	}
	return result == noErr;
}
 void CompoundVector::ElementWiseMinImpl(const Vector& x)
 {
   DBG_START_METH("CompoundVector::ElementWiseMinImpl", dbg_verbosity);
   DBG_ASSERT(vectors_valid_);
   const CompoundVector* comp_x = static_cast<const CompoundVector*>(&x);
   DBG_ASSERT(dynamic_cast<const CompoundVector*>(&x));
   DBG_ASSERT(NComps() == comp_x->NComps());
   for (Index i=0; i<NComps(); i++) {
     Comp(i)->ElementWiseMin(*comp_x->GetComp(i));
   }
 }