Пример #1
0
static inline void
swap(heap_t *hp, int i, int j)
{
        int t = elt(hp, i);
        elt(hp, i) = elt(hp, j);
        elt(hp, j) = t;
}
Пример #2
0
bool s_TestCache(TCache&                    cache,
                 typename TCache::TSizeType data_size,
                 typename TCache::TSizeType cache_size)
{
    typedef typename TCache::TSizeType TSize;
    for (Uint8 i = 1; i < 2*cache_size; i++) {
        if ( !cache.Get(i) ) {
            TElement elt(new CElement(size_t(data_size)));
            cache.Add(i, elt, TSize(i%5));
        }
    }
    if (TSize(2*cache_size) > 0) {
        cache.SetCapacity(TSize(2*cache_size));
    }
    else {
        cache.SetCapacity(cache_size/2);
    }
    for (Uint8 i = 3*cache_size; i > 0; i--) {
        if ( !cache.Get(i) ) {
            TElement elt(new CElement(size_t(data_size)));
            cache.Add(i, elt);
        }
    }
    for (Uint8 i = 0; i < 3*cache_size; i++) {
        cache.Get(i);
    }
    cache.SetCapacity(cache_size);

    return true;
}
Пример #3
0
//Nestable list elements
bool Tag::parseListBlock( Lexer* lexer, Lexer::Token& tok )
{
    bool notHandled( false );
    if( tok == Lexer::TAG ) {
        switch( lexer->tagId() ) {
        //make new tag
        //append pointer to this tag's list
        case Lexer::DL:
            {
                Element* elt( new Dl( document, this, document->dataName(),
                    document->lexerLine(), document->lexerCol(), 0, document->leftMargin() ) );
                appendChild( elt );
                tok = elt->parse( lexer );
            }
            break;
        case Lexer::OL:
            {
                Element* elt( new Ol( document, this, document->dataName(),
                    document->dataLine(), document->dataCol(), 0, document->leftMargin() ) );
                appendChild( elt );
                tok = elt->parse( lexer );
            }
            break;
        case Lexer::PARML:
                {
                    Element* elt( new Parml( document, this, document->dataName(),
                        document->dataLine(), document->dataCol(), 0, document->leftMargin() ) );
                    appendChild( elt );
                    tok = elt->parse( lexer );
                }
            break;
        case Lexer::SL:
            {
                Element* elt( new Sl( document, this, document->dataName(),
                    document->dataLine(), document->dataCol(), 0, document->leftMargin() ) );
                appendChild( elt );
                tok = elt->parse( lexer );
            }
            break;
        case Lexer::UL:
            {
                Element* elt( new Ul( document, this, document->dataName(),
                    document->dataLine(), document->dataCol(), 0, document->leftMargin() ) );
                appendChild( elt );
                tok = elt->parse( lexer );
            }
            break;
        default:
            notHandled = true;
            break;
        }
    }
    return notHandled;
}
Пример #4
0
    /* fonction auxiliaire */
int palindrome_recur_aux(liste l, int ind1, int ind2) {
	// fin de traitement, la liste est un palindrome
	if (ind1 >= ind2) { return 1; }
	
	// pas un palindrome
	if (elt(ind1, l) != elt(ind2, l)) { return 0; }
	
	// sinon on poursuit le test
	return palindrome_recur_aux(l, ind1+1, ind2-1); 
	
}
Пример #5
0
  /* version iterative */
int palindrome_iter(liste l) {
	int result = 1; // par defaut l est un palindrome (jusqu a preuve du contraire)
	// ind1 : indice de debut, ind2 : indice de fin
	int ind1 = 0, ind2 = taille(l)-1;
	
	result = 1;
	while (ind1 < ind2 && result == 1) {
		if (elt(ind1, l) != elt(ind2, l)) {
			result = 0;
		}
		++ind1;
		--ind2;
	}
	return result;
}
Пример #6
0
liste trie(liste l) {
	liste l_result=nouvListe();

	// pour chaque element de l
	int i, ind, cur;
	for(i=0; i < taille(l); ++i) {
		cur = elt(i, l);  // l'element a placer
		// recherche dans l_result l'indice ou placer cur
		ind=0;
		while(ind < taille(l_result) && elt(ind, l_result) < cur) { ++ind; }
		
		insert(cur, l_result, ind);
	}
	return l_result;
}
Пример #7
0
 /** Convert arbitrary conditon objects containing standard tags
  *
  *    Function entry expects as a parameter a valid DetElement handle
  *    pointing to the subdetector, which detector elements should be 
  *    realigned.
  *
  *      <temperature path="/world/TPC" name="AbientTemperatur" value="20.9*Celcius"/>
  *      <temperature path="TPC" name="AbientTemperatur" value="20.9*Celcius"/>
  *      <temperature name="AbientTemperatur" value="20.9*Celcius"/>
  *
  *      <temperature name="AbientTemperatur" value="20.9*Kelvin"/>
  *      <pressure name="external_pressure" value="980*hPa"/>
  *      <include ref="..."/>
  *
  *    The object tag name is passed as the conditons type to the system.
  *    The data payload may either be specified as an attribute to the
  *    element or as text (data payload as the inner XML of the element).
  *
  *  These items have:
  *  - a name defining the condition within the detector element
  *  - a value interpreted as a double. In XML the value may be dressed with a unit
  *    which will be correctly treated by the expression evaluator
  *  - a path (optionally). attribute_values are ALWAYS treated within the context
  *    of the containing detector element. If pathes are relative, they are 
  *    relative to the embedding element. If pathes are absolute, the embedding
  *    element is ignored.
  *
  *  @author  M.Frank
  *  @version 1.0
  *  @date    01/04/2014
  */
 template <> void Converter<arbitrary>::operator()(xml_h e) const {
   xml_comp_t elt(e);
   string tag = elt.tag();
   if ( tag == "open_transaction" )
     return;
   else if ( tag == "close_transaction" ) 
     return;
   else if ( tag == "include" )
     Converter<include>(lcdd,param)(e);
   else if ( tag == "conditions" )  
     Converter<conditions>(lcdd,param)(e);
   else if ( tag == "detelement" )
     Converter<conditions>(lcdd,param)(e);
   else if ( tag == "subdetectors" )
     xml_coll_t(e,_U(star)).for_each(Converter<conditions>(lcdd,param));
   else if ( tag == "detelements" )
     xml_coll_t(e,_U(star)).for_each(Converter<conditions>(lcdd,param));
   else if ( tag == "alignment" )   {
     dd4hep_ptr<Entry> val(_createStackEntry(param,e));
     val->value = elt.attr<string>(_U(ref));
     _getArgs(param)->stack->push_back(val.release());
   }
   else  {
     dd4hep_ptr<Entry> val(_createStackEntry(param,e));
     val->value = elt.hasAttr(_U(value)) ? elt.valueStr() : e.text();
     _getArgs(param)->stack->push_back(val.release());
   }
 }
Пример #8
0
int selectDevice(int devNum)
{
    /* Valid to select nullDevice, but that will open a new device.
       See ?dev.set.
     */
    if((devNum >= 0) && (devNum < R_MaxDevices) &&
       (R_Devices[devNum] != NULL) && active[devNum])
    {
	pGEDevDesc gdd;

	if (!NoDevices()) {
	    pGEDevDesc oldd = GEcurrentDevice();
	    if (oldd->dev->deactivate) oldd->dev->deactivate(oldd->dev);
	}

	R_CurrentDevice = devNum;

	/* maintain .Device */
	gsetVar(R_DeviceSymbol,
		elt(getSymbolValue(R_DevicesSymbol), devNum),
		R_BaseEnv);

	gdd = GEcurrentDevice(); /* will start a device if current is null */
	if (!NoDevices()) /* which it always will be */
	    if (gdd->dev->activate) gdd->dev->activate(gdd->dev);
	return devNum;
    }
    else
	return selectDevice(nextDevice(devNum));
}
Пример #9
0
void affiche(liste l) {
	int i;
	
	for(i=0; i < taille(l); ++i) {
		printf("%d ", elt(i, l));
	}
	printf("\n");
}
Пример #10
0
liste concatenation(liste l1, liste l2) {
	liste l_result;
	 
	l_result = nouvListe();
	int i;
	// ajout de chaque element de l1 
	for(i=0; i < taille(l1); ++i) {
		adjq(elt(i,l1), l_result);
	}
	
    // ajout de chaque element de l2
	for(i=0; i < taille(l2); ++i) {
	    adjq(elt(i,l2), l_result);
	}
	 
	return l_result;
}
Пример #11
0
// Allocates memory
void growable_array::add(cell elt_) {
  factor_vm* parent = elements.parent;
  data_root<object> elt(elt_, parent);
  if (count == array_capacity(elements.untagged()))
    elements = parent->reallot_array(elements.untagged(), count * 2);

  parent->set_array_nth(elements.untagged(), count++, elt.value());
}
Пример #12
0
void
max_heapify(heap_t *hp, size_t i)
{
        size_t l, r, max;

        for (;;) {
                l = left(i);
                r = right(i);
                max = (l <= hp->size && elt(hp, l) > elt(hp, i) ? l : i);
                if (r <= hp->size && elt(hp, r) > elt(hp, max))
                        max = r;
                if (max == i)
                        break;
                swap(hp, i, max);
                i = max;
        }
}
Пример #13
0
BasicIterator<char>& RopePiece::Iterator::operator--() {
  if (stack_.empty()) {
    return *this;
  }

  RopePiece::Iterator::StackElement& top = stack_.top();
  // assert: stack_.top().rope_->string_ != nullptr
  if (top.index_ > 0) {
    top.index_--;
    return *this;
  }

  stack_.pop();
  if (!stack_.empty()) {
    top = stack_.top();
  }

  while (!stack_.empty() && (top.index_ == 0)) {
    // It's possible in this manner to clear out the stack,
    // in which case, we end up going "before" the beginning of
    // the iterator, which is treated the same as the end() iterator.
    stack_.pop();
    if (!stack_.empty()) {
      top = stack_.top();
    }
  }

  if (stack_.empty()) {
    return *this;
  }

  // assert: top.index_ > 0.
  // Now, we will force it to 0, because we will push its prefix on the stack.
  top.index_ = 0;
  StackElement elt(nullptr, 0);
  elt.rope_ = top.rope_->prefix_.get();
  elt.index_ = ((elt.rope_->string_ == nullptr) ?
                (elt.rope_->prefix_.get() == nullptr ?
                 0 : elt.rope_->prefix_->length() - 1) :
                 (elt.rope_->length() - 1));
  stack_.push(elt);
  while (elt.rope_->string_ == nullptr) {
    // Inside the loop, we push the suffix for the current element onto
    // the stack. The premise being that we want the end of the current
    // rope in the stack frame. Of course, if the suffix is null, we
    // use the prefix instead.
    elt.rope_ = (elt.rope_->suffix_.get() == nullptr ?
                 elt.rope_->prefix_.get() : elt.rope_->suffix_.get());
    elt.index_ = ((elt.rope_->string_ == nullptr) ?
                  (elt.rope_->prefix_.get() == nullptr ?
                   0 : elt.rope_->prefix_->length() - 1) :
                   (elt.rope_->length() - 1));
    stack_.push(elt);
  }

  // assert: elt.rope_->string_ != nullptr, and elt is already on the stack.
  return *this;
}
Пример #14
0
int cherche(int nb, liste l) {
	int ind=-1;
	int i;
	 
	for(i=0;i<taille(l) && ind == -1;++i) {
		 if (elt(i, l) == nb) { ind = i; }
	}
	 
	return ind;
}
Пример #15
0
int HESS_B (double *x, double *H)
{
  int i, j, index_x, index_y;

  FillStructs_B (x);

  for (i=0; i < (2*n + 3*(m-1)); ++i) 
    for (j=0; j <= i; ++j)
      H[elt(i, j)] = 0.0;
  
  for (j=0; j < m; ++j)
    for (i=0; i < n; ++i) {
      
      for (index_x=THETA; index_x <= OMEGA; ++index_x)
	for (index_y=THETA; index_y <= index_x; ++index_y)
	  H[elt(2*i+(index_x-THETA), 2*i+(index_y-THETA))] +=
	    Hessian1 (TheEdges[j][i],
		      TheCameraPositions[j],
		      TheLines[i],
		      index_x, index_y);
      
      if (j) {
	for (index_x=THETA; index_x <= OMEGA; ++index_x)
	  for (index_y=ALPHA; index_y <= GAMMA; ++index_y)
	    H[elt(2*i+(index_x-THETA), 2*n+(j-1)*3+(index_y-ALPHA))] +=
	      Hessian1 (TheEdges[j][i],
			TheCameraPositions[j],
			TheLines[i],
			index_x, index_y);
	
	for (index_x=ALPHA; index_x <= GAMMA; ++index_x)
	  for (index_y=ALPHA; index_y <= index_x; ++index_y)
	    H[elt(2*n+(j-1)*3+(index_x-ALPHA), 2*n+(j-1)*3+(index_y-ALPHA))] +=
	      Hessian1 (TheEdges[j][i],
			TheCameraPositions[j],
			TheLines[i],
			index_x, index_y);
      }
    }

	return 0;
}
Пример #16
0
int nbOccurences(int nb, liste l) {
	int nboccur=0; 	// compteur
	int i;
	 
	// pour chaque element de la liste
	for(i=0;i<taille(l);++i) {
		 if (elt(i, l) == nb) { nboccur++; }
	}
	
	return nboccur;
}
Пример #17
0
  /* version iterative */
liste renverse_iter(liste l) {
	liste l_result = nouvListe();
	
	int i=0, fin = taille(l);
	
	while(i < fin) {
		adjt(elt(i, l), l_result);
		++i;
	}
	
	return l_result;
}
// ********************************************************************
// seq
//
// Recursively trys to parse a sequence from the grammar.
// ********************************************************************
void RecursiveDescentParser::seq()
{
	// attempts to parse out an element
	elt();

	// match a sequence separator and attempt to parse out another sequence
	if (current_token.type == ',') 
	{
		match(',');
		seq();
	}
}
Пример #19
0
liste interclasse(liste l1, liste l2) {
	// liste resultat
	liste l_result = nouvListe();
	
	// indice courant l1 et l2
	int ind1 = 0, ind2 = 0;
	int t1 = taille(l1), t2 = taille(l2);
	 
	// tq fin d'une des listes non atteinte
	while (ind1 < t1 && ind2 < t2) {
		if (elt(ind1, l1) < elt(ind2, l2)) {
			adjq(elt(ind1, l1), l_result); 
			++ind1;
		} else {
			adjq(elt(ind2, l2), l_result); 
			++ind2;
		}
	}
	
	// on est arrive a la fin d'une des deux listes, dans la suite, on entre dans un seul while
	
	while (ind1 < t1) { 
		adjq(elt(ind1, l1), l_result); 
		++ind1;
	}
	
	while (ind2 < t2) { 
		adjq(elt(ind2, l2), l_result); 
		++ind2;
	}
	
	return l_result;
}
Пример #20
0
BasicIterator<char>& RopePiece::Iterator::operator++() {
  if (stack_.empty()) {
    return *this;
  }

  RopePiece::Iterator::StackElement& top = stack_.top();
  // assert: stack_.top().rope_->string_ != nullptr
  if (top.index_ + 1 < top.rope_->length()) {
    top.index_++;
    return *this;
  }

  stack_.pop();
  if (!stack_.empty()) {
    top = stack_.top();
  }

  while (!stack_.empty() &&
         (top.index_ > 0 ||
          top.rope_->prefix_ == nullptr ||
          top.rope_->prefix_->length() == 0 ||
          top.rope_->suffix_ == nullptr ||
          top.rope_->suffix_->length() == 0)) {
    stack_.pop();
    if (!stack_.empty()) {
      top = stack_.top();
    }
  }

  if (stack_.empty()) {
    return *this;
  }

  // assert: top.rope_->prefix_->length() > 0 && top.index_ == 0
  //         top.rope_->suffix_->length() > 0
  top.index_ = top.rope_->prefix_->length();
  StackElement elt(top.rope_->suffix_.get(), 0);
  stack_.push(elt);
  while (elt.rope_->string_ == nullptr) {
    // assert: elt_.rope_->prefix_ != nullptr || elt_.rope_->suffix_ != nullptr
    // The reason we can make this assertion is that the length of the rope
    // would be 0, contradicting an earlier assumption that the rope has more
    // characters.
    elt.rope_ = (elt.rope_->prefix_.get() == nullptr ?
                 elt.rope_->suffix_.get() : elt.rope_->prefix_.get());
    stack_.push(elt);
  }

  // assert: elt.rope_->string_ != nullptr, and elt is already on the stack.

  return *this;
}
Пример #21
0
RopePiece::Iterator::Iterator(const RopePiece* container, uint32_t index) :
    stack_(), saved_tmp_(nullptr) {
  if (container == nullptr || index >= container->length()) {
    return;
  }

  if (container->string_ != nullptr) {
    RopePiece::Iterator::StackElement elt(container, index);
    stack_.push(elt);
    return;
  }

  const RopePiece* elt_rope = container;
  uint32_t elt_index = index;
  while (elt_rope->string_ == nullptr) {
    if (elt_rope->prefix_ == nullptr) {
      RopePiece::Iterator::StackElement elt(elt_rope, 0);
      stack_.push(elt);
      elt_rope = elt_rope->suffix_.get();
    } else if (elt_rope->prefix_->length() <= elt_index) {
      // assert: elt_rope->suffix_ != nullptr.
      // Suffix contains offset into RopePiece of interest.
      uint32_t prefix_len = elt_rope->prefix_->length();
      RopePiece::Iterator::StackElement elt(elt_rope, prefix_len);
      stack_.push(elt);
      elt_rope = elt_rope->suffix_.get();
      elt_index -= prefix_len;
    } else {
      // assert: elt_rope->prefix_->length() > elt_index, so prefix
      // contains offset into RopePiece of interest.
      RopePiece::Iterator::StackElement elt(elt_rope, 0);
      stack_.push(elt);
      elt_rope = elt_rope->prefix_.get();
    }
  }

  RopePiece::Iterator::StackElement elt(elt_rope, elt_index);
  stack_.push(elt);
}
//return menu shortcut: Ctrl+F or Ctrl+Shift+L
NS_IMETHODIMP
nsXULMenuitemAccessible::GetDefaultKeyBinding(nsAString& aKeyBinding)
{
  aKeyBinding.Truncate();

  nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
  NS_ENSURE_TRUE(elt, NS_ERROR_FAILURE);

  nsAutoString accelText;
  elt->GetAttribute(NS_LITERAL_STRING("acceltext"), accelText);
  if (accelText.IsEmpty())
    return NS_OK;

  aKeyBinding = accelText;

  return NS_OK;
}
//return menu accesskey: N or Alt+F
NS_IMETHODIMP
nsXULMenuitemAccessible::GetKeyboardShortcut(nsAString& aAccessKey)
{
  aAccessKey.Truncate();

  static PRInt32 gMenuAccesskeyModifier = -1;  // magic value of -1 indicates unitialized state

  nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(mDOMNode));
  if (elt) {
    nsAutoString accesskey;
    // We do not use nsAccUtils::GetAccesskeyFor() because accesskeys for
    // menu are't registered by nsIEventStateManager.
    elt->GetAttribute(NS_LITERAL_STRING("accesskey"), accesskey);
    if (accesskey.IsEmpty())
      return NS_OK;

    nsCOMPtr<nsIAccessible> parentAccessible(GetParent());
    if (parentAccessible) {
      PRUint32 role;
      parentAccessible->GetRole(&role);
      if (role == nsIAccessibleRole::ROLE_MENUBAR) {
        // If top level menu item, add Alt+ or whatever modifier text to string
        // No need to cache pref service, this happens rarely
        if (gMenuAccesskeyModifier == -1) {
          // Need to initialize cached global accesskey pref
          gMenuAccesskeyModifier = 0;
          nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
          if (prefBranch)
            prefBranch->GetIntPref("ui.key.menuAccessKey", &gMenuAccesskeyModifier);
        }
        nsAutoString propertyKey;
        switch (gMenuAccesskeyModifier) {
          case nsIDOMKeyEvent::DOM_VK_CONTROL: propertyKey.AssignLiteral("VK_CONTROL"); break;
          case nsIDOMKeyEvent::DOM_VK_ALT: propertyKey.AssignLiteral("VK_ALT"); break;
          case nsIDOMKeyEvent::DOM_VK_META: propertyKey.AssignLiteral("VK_META"); break;
        }
        if (!propertyKey.IsEmpty())
          nsAccessible::GetFullKeyName(propertyKey, accesskey, aAccessKey);
      }
    }
    if (aAccessKey.IsEmpty())
      aAccessKey = accesskey;
    return NS_OK;
  }
  return NS_ERROR_FAILURE;
}
Пример #24
0
static PyObject *
convert_values_to_python (int argc, struct value **argv)
{
  int i;
  gdbpy_ref<> result (PyTuple_New (argc));

  if (result == NULL)
    return NULL;

  for (i = 0; i < argc; ++i)
    {
      gdbpy_ref<> elt (value_to_value_object (argv[i]));
      if (elt == NULL)
	return NULL;
      PyTuple_SetItem (result.get (), i, elt.release ());
    }
  return result.release ();
}
Пример #25
0
NS_IMETHODIMP
nsMenuFrame::GetActiveChild(nsIDOMElement** aResult)
{
  if (!mPopupFrame)
    return NS_ERROR_FAILURE;

  nsMenuFrame* menuFrame = mPopupFrame->GetCurrentMenuItem();
  if (!menuFrame) {
    *aResult = nsnull;
  }
  else {
    nsCOMPtr<nsIDOMElement> elt(do_QueryInterface(menuFrame->GetContent()));
    *aResult = elt;
    NS_IF_ADDREF(*aResult);
  }

  return NS_OK;
}
Пример #26
0
Lexer::Token SlLi::parse( Lexer* lexer )
{
    Lexer::Token tok( parseAttributes( lexer ) );
    while( tok != Lexer::END && !( tok == Lexer::TAG && lexer->tagId() == Lexer::EUSERDOC ) ) {
        if( parseInline( lexer, tok ) ) {
            if( lexer->tagId() == Lexer::LI )
                break;
            else if( lexer->tagId() == Lexer::LP ) {
                Element* elt( new P( document, this, document->dataName(),
                    document->dataLine(), document->dataCol() ) );
                appendChild( elt );
                tok = elt->parse( lexer );
            }
            else if( parseBlock( lexer, tok ) )
                break;
        }
    }
    return tok;
}
Пример #27
0
// 1 - Simple event loop thread test
void Test_1 (TAO_ORB_Core* orb_core)
{
  TAO_LF_Strategy &lf_strategy = orb_core->lf_strategy ();
  TAO_Leader_Follower &leader_follower = orb_core->leader_follower ();
  TAO_ORB_Core_TSS_Resources* tss = orb_core->get_tss_resources ();

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("==========\n")));
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TEST #1 - Simple Event Loop call\n")));

  TSS_ASSERT (tss, leader_follower, 0, 0, false);

  std::auto_ptr<TAO_LF_Event_Loop_Thread_Helper>
    elt (new TAO_LF_Event_Loop_Thread_Helper(leader_follower,
                                             lf_strategy,
                                             0));
  TSS_ASSERT (tss, leader_follower, 1, 0, true);

  elt.reset (0);
  TSS_ASSERT (tss, leader_follower, 0, 0, false);
}
Пример #28
0
rtx
rtx_vector_builder::build ()
{
  finalize ();

  rtx x = find_cached_value ();
  if (x)
    return x;

  unsigned int nelts;
  if (!GET_MODE_NUNITS (m_mode).is_constant (&nelts))
    nelts = encoded_nelts ();
  rtvec v = rtvec_alloc (nelts);
  for (unsigned int i = 0; i < nelts; ++i)
    RTVEC_ELT (v, i) = elt (i);
  x = gen_rtx_raw_CONST_VECTOR (m_mode, v);
  CONST_VECTOR_NPATTERNS (x) = npatterns ();
  CONST_VECTOR_NELTS_PER_PATTERN (x) = nelts_per_pattern ();
  return x;
}
Пример #29
0
/* historically the close was in the [kK]illDevices.
   only use findNext = FALSE when shutting R dowm, and .Device[s] are not
   updated.
*/
static
void removeDevice(int devNum, Rboolean findNext)
{
    /* Not vaild to remove nullDevice */
    if((devNum > 0) && (devNum < R_MaxDevices) &&
       (R_Devices[devNum] != NULL) && active[devNum])
    {
	int i;
	SEXP s;
	pGEDevDesc g = R_Devices[devNum];

	active[devNum] = FALSE; /* stops it being selected again */
	R_NumDevices--;

	if(findNext) {
	    /* maintain .Devices */
	    PROTECT(s = getSymbolValue(R_DevicesSymbol));
	    for (i = 0; i < devNum; i++) s = CDR(s);
	    SETCAR(s, mkString(""));
	    UNPROTECT(1);

	    /* determine new current device */
	    if (devNum == R_CurrentDevice) {
		R_CurrentDevice = nextDevice(R_CurrentDevice);
		/* maintain .Device */
		gsetVar(R_DeviceSymbol,
			elt(getSymbolValue(R_DevicesSymbol), R_CurrentDevice),
			R_BaseEnv);

		/* activate new current device */
		if (R_CurrentDevice) {
		    pGEDevDesc gdd = GEcurrentDevice();
		    if(gdd->dev->activate) gdd->dev->activate(gdd->dev);
		}
	    }
	}
	g->dev->close(g->dev);
	GEdestroyDevDesc(g);
	R_Devices[devNum] = NULL;
    }
}
Пример #30
0
/**
 * Construct search list based on distribution type.
 *
 * Here n=numElements is equal to z^2 and we intend to fill up the 
 * elements of searchList with all elements from ds. Draw the elements
 * themselves from elementsInC.
 *
 * p can be one of {0.0,0.25,0.5,0.75,1.0} and we deal with accordingly
 * in this method. Note there is no need to be random about anything since
 * we are going to aggregate over all elements in the set C and everyone
 * will eventually be searched for.
 *
 * the searchlist is randomly shuffled 12*z times to ensure some bit of 
 * randomness...
 */
static void constructSearchList() {
  int i,j,k;
  searchList = (char **) calloc (numElements, sizeof(char *));
  
  if (distrib == UNIFORM) {
    int ct = 0;
    int toReplace = (1-p)*numElements;
    int max_k_minus_one = (int) pow (2, elementSize-1); /* strings not in Sk */
    int numToShuffle = 12*z;

    /* populate all 24*z with elements of C */
    for (i = 0; i < 24; i++) {
      for (j = 0; j < z; j++) {
	searchList[ct++] = elementsInC[j];
      }
    }

    /* Now take 'p' into account and switch p*24*z with a random string from
     * the set S_{k-1}. */
    for (i = 0; i < toReplace; i++) {
      j = (int) (max_k_minus_one * (rand() / (RAND_MAX + 1.0)));
      searchList[i] = elt(elementSize-1,j);
    }

    /* now randomly shuffle 12*z points within the 24*z array. */
    for (i = 0; i < numToShuffle; i++) {
      char *t;
      j = (int) (numElements * (rand() / (RAND_MAX + 1.0)));
      k = (int) (numElements * (rand() / (RAND_MAX + 1.0)));

      t = searchList[j];
      searchList[j] = searchList[k];
      searchList[k] = t;
    }

  } else {
    printf ("** Only UNIFORM distribution implemented to date **");
  }
}