示例#1
0
/**
 * @brief Aleatorio::Aleatorio
 * @param url path of directory
 * @param w_Label
 */
Aleatorio::Aleatorio(const QString url, QLabel *w_Label)
{
    Path=url;
    QFile fexiste( url + "/index.dat" );//comprobamos si hay fichero indice

    if(!fexiste.exists())//si no existe  creamos el indice
    {
        this->CrearIndice(url);
        fexiste.close();
    }

   /* QFile file( url + "/index.dat");//leemos el fichero indice que contiene los paht+file
    file.open( QIODevice::ReadOnly );

    QDataStream stream( &file );
    stream.setVersion( QDataStream::Qt_4_2 );

    stream >> results;//lo cargamos en qlist para hacer la lista

    file.close();*/
    TotalFicheros=this->Count(url);


    if(TotalFicheros==1){// solo hay 1 para pobcast

        DeleteIndex();
        CrearIndice(Path);// creamos nuevo para pobcast
        TotalFicheros=this->Count(url);

    }



}
示例#2
0
bool csMovableSectorList::Remove (int n)
{
  iSector* obj = Get (n);
  csMeshWrapper* object = movable->GetMeshWrapper ();
  if (object) object->RemoveFromSectors (obj);
  return DeleteIndex (n);
}
示例#3
0
bool Container::Delete(TUInt32 entry)
{
	// Look for the entry
	for(TUInt32 i=0;i<mCurNbEntries;i++)
	{
		if(mEntries[i]==entry)
		{
			// Entry has been found at index i. The strategy is to copy the last current entry at index i, and decrement the current number of entries.
			DeleteIndex(i);
			return true;
		}
	}
	return false;
}
示例#4
0
    void IpPool::KickTrivialCandidatePeers()
    {
        if (!desirable_pool_size_ ||
            candidate_peers_.empty())
        {
            return;
        }
            
        size_t peers_to_delete = 0;
        if (candidate_peers_.size() > desirable_pool_size_)
        {
            peers_to_delete = candidate_peers_.size() - desirable_pool_size_;
        }

        size_t peers_deleted = 0;
        size_t max_connection_attempts_allowed = desirable_pool_size_/this->candidate_peers_.size();

        for(std::map<ActiveIndicator, CandidatePeer::p>::iterator iter = active_index_.begin();
            iter != active_index_.end() && peers_deleted < peers_to_delete;)
        {
            CandidatePeer::p peer = iter->second;
            ++iter;

            if (!peer->is_connected_ && !peer->is_connecting_)
            {
                bool too_many_connection_attempts = peer->connections_attempted_ > max_connection_attempts_allowed;

                if (too_many_connection_attempts)
                {
                    assert(black_list_.find(peer->GetKey()) ==  black_list_.end());
                    black_list_.insert(peer->GetKey());
                }

                if (peers_deleted < peers_to_delete ||
                    too_many_connection_attempts)
                {
                    DeleteIndex(peer);
                    candidate_peers_.erase(peer->GetKey());
                    ++peers_deleted;
                }
            }
        }

        if (peers_deleted)
        {
            DebugLog("IpPool::KickTrivialCandidatePeers: kicked %d peers.", peers_deleted);
        }
    }
void CEsmRefCellPage::OnCellrefUndelete() {
  DEFINE_FUNCTION("CEsmRefCellPage::OnCellrefDelete()");
  POSITION	  SelPos;
  int		  SelectedIndex;
  
	/* Delete all selected records */
  SelPos = m_CellRefList.GetFirstSelectedItemPosition();

  while (SelPos != NULL) {
    SelectedIndex = m_CellRefList.GetNextSelectedItem(SelPos);
    DeleteIndex(SelectedIndex, false);
   }

	/* Update the display */
  UpdateCellRefList();
 }
示例#6
0
/**
 * This function select ramdon file from path
 * @brief Aleatorio::FicheroPath
 * @return the path of random filename
 */
QString Aleatorio::FicheroPath()
{

    if(TotalFicheros==0){// no hay ficheros en la carpeta
         DeleteIndex();
        return("--- error en carpeta --");
    }


    int Cual;
        Cual=NumeroAleatorio(0,TotalFicheros-1);

    while (!Repetido(Cual))
        Cual=NumeroAleatorio(0,TotalFicheros-1);

    Todos();//checks if all has played
    Cancion=results[Cual];//for titles

    return(results[Cual]);
}
void EditableTextComponent::keyTyped(const KeyEventUnrecPtr e)
{
	
    if(getEnabled() && getEditable() && !(e->getModifiers() &( KeyEvent::KEY_MODIFIER_ALT | KeyEvent::KEY_MODIFIER_CONTROL | KeyEvent::KEY_MODIFIER_META )))
	{
		if(e->getKeyChar()>31 && e->getKeyChar() < 127)
		{
			if(hasSelection())
			{
                deleteSelectedText();
				setCaretPosition(_TextSelectionStart);
			}
            insert(std::string( 1,e->getKeyChar() ), _TextSelectionStart);
			_TextSelectionStart = getCaretPosition();
			_TextSelectionEnd = _TextSelectionStart;
		}
		if(e->getKey()== e->KEY_BACK_SPACE)
		{
			if(hasSelection())
			{
                deleteSelectedText();
			}
			else
			{	
                //erase at the current caret position
                Int32 DeleteIndex(getCaretPosition());
                if(DeleteIndex != 0)
                {
                    moveCaret(-1);
                    deleteRange(DeleteIndex-1, DeleteIndex);
                }
			}
		}
		if(e->getKey()== e->KEY_DELETE)
		{
			if(hasSelection())
			{
                deleteSelectedText();
			}
			else if(getText().size()>0)
			{
				//erase at the current caret position
                deleteRange(getCaretPosition(), getCaretPosition()+1);
				_TextSelectionStart = getCaretPosition();
				_TextSelectionEnd = _TextSelectionStart;
			}
		}
	}
	
    switch(e->getKey())
    {
    case KeyEvent::KEY_RIGHT:
    case KeyEvent::KEY_KEYPAD_RIGHT:
        moveCaret(1);
        break;
    case KeyEvent::KEY_LEFT:
    case KeyEvent::KEY_KEYPAD_LEFT:
        moveCaret(-1);
        break;
    case KeyEvent::KEY_V:
        if(e->getModifiers() & KeyEvent::KEY_MODIFIER_COMMAND)
        {
            paste();
        }
        break;
    case KeyEvent::KEY_C:
        if(e->getModifiers() & KeyEvent::KEY_MODIFIER_COMMAND)
        {
            copy();
        }
        break;
    case KeyEvent::KEY_X:
        if(e->getModifiers() & KeyEvent::KEY_MODIFIER_COMMAND)
        {
            cut();
        }
        break;
    case KeyEvent::KEY_A:
        if(e->getModifiers() & KeyEvent::KEY_MODIFIER_COMMAND)
        {
            selectAll();
        }
        break;
    }

	Inherited::keyTyped(e);
}
示例#8
0
文件: main.cpp 项目: elff1/myCodes
int main(void){
	int i, j, tmp;
	const int size = 10;
	vector<int>::iterator vi;
	Address a;
	TKey ans;
	BaseNode *p = NULL;
	int data[size] = {5, 2, 7, 1, 9, 4, 0, 6, 3, 8};
	vector<int> v(data, data+size);
	vector<int> vn;
	time_t t_start, t_end;

	// Initialize
	for(i = 0; i < BlockNum; i++)
		blockUsed[i] = false;
	for(i = 0; i < IndexNum; i++)
		indexRootBlockId[i] = -1;
	for(i = 0; i < IndexNum; i++)
		indexDataBlockId[i] = -1;
	for(i = 0; i < IndexNum; i++)
		indexType[i] = TYPE_INT;
	
	for(i = 0; i < DATA_NUM; i++)
		vn.push_back(i);
	srand((unsigned int)time(0));
	for(i = 0; i < DATA_NUM; i++){
		j = rand() % DATA_NUM;
		tmp = vn.at(j);
		vn.erase(vn.begin() + j);
		vn.push_back(tmp);
	}
	/*for(i = 0; i < DATA_NUM; i++){
		cout << vn.at(i) << ' ';
	}
	system("pause");
	return 0;*/

	// test
	try{
		cout << "----------------insert " << DATA_NUM << " numbers----------------------" << endl;
		time(&t_start);
		//for(i = 0; i < 15; i++){
		//for(i = DATA_NUM; i >= 0; i--){
		for(vi = vn.begin(); vi != vn.end(); vi++){
			i = *vi;
			if(!(i % (DATA_NUM / PRINT_NUM)))
				cout << "-------------insert " << i << "---------------" << endl;
			try{
				a = InsertIndex(0, 0, TKey(i));
			}
			catch(ErKeyNotFound &e){
				cout << e.what() << e.key() << endl;
			}
			catch(DbEr &e){
				cout << e.what() << endl;
			}
			//p = (BaseNode *)GetBlock(a.blockId);

			//cout << "Insert Data Block: " << a.blockId << endl;

			//p->data[a.offset] = i;

			//PrintIndex(GetRootBlockId(0), p);
			//PrintCatalog();
		}
		time(&t_end);
		cout << "Run time for insert " << DATA_NUM << " data: " << t_end - t_start << "s" << endl;
		//PrintData(0, p);
		//PrintIndex(GetRootBlockId(0), p);

		cout << "----------------query " << DATA_NUM << " numbers----------------------" << endl;
		time(&t_start);
		//for(i = 0; i <= DATA_NUM; i++){
		for(vi = vn.begin(); vi != vn.end(); vi++){
			i = *vi;
			if(!(i % (DATA_NUM / PRINT_NUM)))
				cout << "-------------query " << i << "----------------" << endl;
			try{
				a = FindIndex(0, 0, TKey(i));
				p = (BaseNode *)GetBlock(a.blockId);
				ans = TKey(p->Key(a.offset), p->type);
				if(ans.iKey != i){
					throw ErKeyNotFound(TKey(i));
				}
			}
			catch(ErKeyNotFound &e){
				cout << e.what() << e.key() << endl;
			}
			catch(DbEr &e){
				cout << e.what() << endl;
			}

			//PrintIndex(GetRootBlockId(0), p);
			//PrintCatalog();
		}
		time(&t_end);
		cout << "Run time for query " << DATA_NUM << " data: " << t_end - t_start << "s" << endl;
		PrintCatalog();

		cout << "----------------delete " << DATA_NUM << " numbers----------------------" << endl;
		time(&t_start);
		//for(i = 0; i <= DATA_NUM; i++){
		for(vi = vn.begin(); vi != vn.end(); vi++){
			i = *vi;
			if(!(i % (DATA_NUM / PRINT_NUM)))
				cout << "-------------delete " << i << "---------------" << endl;
			try{
				DeleteIndex(0, 0, TKey(i));
			}
			catch(ErKeyNotFound &e){
				cout << e.what() << e.key() << endl;
			}
			catch(DbEr &e){
				cout << e.what() << endl;
			}

			//PrintIndex(GetRootBlockId(0), p);
			//PrintData(GetDataBlockId(0), p);
			//PrintCatalog();
		}
		time(&t_end);
		cout << "Run time for delete " << DATA_NUM << " data: " << t_end - t_start << "s" << endl;

		PrintData(GetDataBlockId(0), p);
		DropIndex(0, 0);
		PrintCatalog();
		/*for(i = 0; i < 15; i++){
			a = FindIndex(0, i);
			cout << "Find \"" << i << "\" in offset " << a.offset
				<< " of Block " << a.blockId << endl;
		}*/
	}
	catch(ErKeyNotFound &e){
		cout << e.what() << e.key() << endl;
	}
	catch(DbEr &e){
		cout << e.what() << endl;
	}

	system("pause");
}
示例#9
0
int main(int argc, char *argv[]) {
  int i, j;
  int record_count = 400;
  int range = record_count/10;
  uint8_t len = 5;
  AttributeType type[len];
  const char hans[] = "hans";
  Index *index;
  Iterator **iterator = (Iterator**) malloc(sizeof(Iterator*));
  Transaction *t;
  Record recs[record_count];
  Key keys[record_count];
  Key minkey;
  Key maxkey;
  Record *currentResult;
  Attribute attr;
  Block blocks[record_count];
  time_t tm;
  
  for (j = 0; j < record_count; j++) {
    blocks[j].size = 5;
    blocks[j].data = malloc(5);
    sprintf((char*)blocks[j].data, "%i", j);
    attr.type = kInt;
    keys[j].value = (Attribute**) malloc(len*sizeof(Attribute*));
    keys[j].attribute_count = len;
//     printf("Key number %i: \n", j);
    for (i = 0; i < len; i++) {
      type[i] = kInt;
      keys[j].value[i] = (Attribute*) malloc(sizeof(Attribute));
      keys[j].value[i]->type = kInt;
      keys[j].value[i]->int_value = randInt(range);
//       printf("key.value[%i] = %ld \n", i, keys[j].value[i]->int_value);
    }
//     printf("\n");
    recs[j].key = keys[j];
    recs[j].payload = blocks[j];
  }
  // generate min and max keys
  minkey.value = (Attribute**) malloc(len*sizeof(Attribute*));
  minkey.attribute_count = len;
  maxkey.value = (Attribute**) malloc(len*sizeof(Attribute*));
  maxkey.attribute_count = len;
  for (i = 0; i < len; i++) {
    minkey.value[i] = (Attribute*) malloc(sizeof(Attribute));
    minkey.value[i]->type = kInt;
    minkey.value[i]->int_value = 0.3*range;
    maxkey.value[i] = (Attribute*) malloc(sizeof(Attribute));
    maxkey.value[i]->type = kInt;
    maxkey.value[i]->int_value = 0.8*range;
  }
  printf("Done with generating data. \n");
  
  tm = time(NULL);
  CreateIndex(hans, len, type); // len
  OpenIndex(hans, &index);
  BeginTransaction(&t);
  for (i = 0; i < record_count; i++) { //record_count
    InsertRecord(t, index, recs+i);
    if (i % 1000 == 0) 
      printf("i = %i / %i \n", i, record_count);
  }
  printf("finished inserting, took %is \n", time(NULL)-tm);
  tm = time(NULL);
//   for (i = 0; i < record_count; i+=2) { // record_count
//     if (i == 398) {
//       printf("deleting record %i \n", i);
//     }
    DeleteRecord(t, index, recs+4, 0);
//   }
//   if (DeleteRecord(t, index, recs+398, 0) != kErrorNotFound) {
//     printf(";_; \n ");
//   }
  printf("deleted half of the records, took %is \n", time(NULL)-tm);
  GetRecords(t, index, minkey, maxkey, iterator);
  while (GetNext(*iterator, &currentResult) != kErrorNotFound) {
    printf("%i \t(%i\t%i\t%i\t%i\t%i)\t%s \n", currentResult->key.value[0]->int_value, currentResult->key.value[0]->int_value, currentResult->key.value[1]->int_value, currentResult->key.value[2]->int_value, currentResult->key.value[3]->int_value, currentResult->key.value[4]->int_value, currentResult->payload.data);
  }
  printf("just to be sure: \n");
  for (i = 0; i < record_count; i++) {
    for (j = 0; j < len; j++) { // len
//       if (!(compareKeys(minkey, keys[i], j, true) <= 0 && compareKeys(keys[i], maxkey, j, true) < 0)) {
	if (!((minkey.value[j] == 0 || compareKeys(minkey, keys[i], j, true) <= 0) && (maxkey.value[j] == 0 || compareKeys(keys[i], maxkey, j, true) < 0))) {
	break;
      }
    }
    if (j == len) { // len
      printf("so: %i \n", keys[i].value[0]->int_value);
    }
  }
//   printf("committing \n");
  CommitTransaction(&t);
//   printf("closing \n");
  CloseIndex(&index);
//   printf("deleting \n");
  DeleteIndex(hans);
//   printf("should be zero: %i \n", all_indices["hans"]);
  return 0;
}