Exemplo n.º 1
0
 int findDuplicate(vector<int>& nums) {
     int n = nums.size();
     int tot = 0;
     for (int i = 0; i < n; i++)
         tot += nums[i];
     n--;
     int l = 1, r = n;
     while (l != r) {
         int m = (l + r) >> 1;
         int lb = (2 * n + 3 - m) * m >> 1;
         int ub = (m * (m + 1) + n * (n + 1)) >> 1;
         if (tot > ub)
             l = m + 1;
         else if (tot < lb)
             r = m - 1;
         else {
             int t = 0;
             while (true) {
                 if (isDup(nums, m + t))
                     return m + t;
                 if (isDup(nums, m - t))
                     return m - t;
                 t++;
             }
         }
     }
     return l;
 }
//------------------------------------------------------------------------------
bool MainWindow::getTargetFile(QListWidget *listWidget, QString fpath, int rest)
{
    bool isContinue = true;
    int dupIndex;

    dupIndex = isDup(listWidget, fpath);
    if (dupIndex != -1) {
        QMessageBox::StandardButton reply;
        if(rest > 0){
            reply = QMessageBox::information(this, tr("Confirm"),
                tr("Duplicate file name. Replace?") + "\n\n" + listWidget->item(dupIndex)->text() + "\n   " + tr("to") + "\n" + fpath,
                QMessageBox::Yes | QMessageBox::No | QMessageBox::Abort);
            if(reply == QMessageBox::Abort){
                isContinue = false;
            }
            else if(reply == QMessageBox::Yes){
                listWidget->item(dupIndex)->setText(fpath);
            }
        }
        else{
            reply = QMessageBox::information(this, tr("Confirm"),
                tr("Duplicate file name. Replace?") + "\n\n" + listWidget->item(dupIndex)->text() + "\n   " + tr("to") + "\n" + fpath,
                QMessageBox::Yes | QMessageBox::No);
            if (reply == QMessageBox::Yes){
                listWidget->item(dupIndex)->setText(fpath);
            }
        }
    }
    else{
        listWidget->addItem(fpath);
    }
    return isContinue;
}
    virtual Status insert(OperationContext* opCtx,
                          const BSONObj& key,
                          const RecordId& loc,
                          bool dupsAllowed) {
        invariant(loc.isNormal());
        invariant(!hasFieldNames(key));

        if (key.objsize() >= TempKeyMaxSize) {
            string msg = mongoutils::str::stream()
                << "EphemeralForTestBtree::insert: key too large to index, failing " << ' '
                << key.objsize() << ' ' << key;
            return Status(ErrorCodes::KeyTooLong, msg);
        }

        // TODO optimization: save the iterator from the dup-check to speed up insert
        if (!dupsAllowed && isDup(*_data, key, loc))
            return dupKeyError(key);

        IndexKeyEntry entry(key.getOwned(), loc);
        if (_data->insert(entry).second) {
            _currentKeySize += key.objsize();
            opCtx->recoveryUnit()->registerChange(new IndexChange(_data, entry, true));
        }
        return Status::OK();
    }
Exemplo n.º 4
0
        virtual Status insert(OperationContext* txn,
                              const BSONObj& key,
                              const DiskLoc& loc,
                              bool dupsAllowed) {

            invariant(!loc.isNull());
            invariant(loc.isValid());
            invariant(!hasFieldNames(key));

            if ( key.objsize() >= TempKeyMaxSize ) {
                string msg = mongoutils::str::stream()
                    << "Heap1Btree::insert: key too large to index, failing "
                    << ' ' << key.objsize() << ' ' << key;
                return Status(ErrorCodes::KeyTooLong, msg);
            }

            // TODO optimization: save the iterator from the dup-check to speed up insert
            if (!dupsAllowed && isDup(*_data, key, loc))
                return dupKeyError(key);

            BSONObj owned = key.getOwned();
            if ( _data->insert(IndexKeyEntry(owned, loc)).second ) {
                _currentKeySize += key.objsize();
                Heap1RecoveryUnit::notifyIndexInsert( txn, this, owned, loc );
            }
            return Status::OK();
        }
Exemplo n.º 5
0
Arquivo: Main.c Projeto: k2b3d/tconsrc
int main(int argc, char *argv[])
{
	pid_t 		pid ;
	int 		stat ;
	pthread_t	pthread_cancel_id, pthread_sms_id, pthread_cois_id ;	
	int			ret ;

	isDup(argv[0]) ;

	if((pid = fork()) < 0)
		return  -1;
	else    if(pid != 0)
		exit(0);

	setsid() ;

	set_signal() ;

	if (argc > 1) {
		if (argc == 3) {
			if (strcmp(argv[1], "-f") == 0) {
				strcpy(config_file_path, argv[2]);
			}
			else    {
				printf("---------------------------------\n");
				printf("-%s [-f ConfigFilePath]\n", argv[0]);
				printf("---------------------------------\n");
				}
			}
		else    {
			printf("---------------------------------\n");
			printf("-%s [-f ConfigFilePath]\n", argv[0]);
			printf("---------------------------------\n");
		}
	}
	else
		sprintf(config_file_path, "../config/TCenter.Config");

	memset(&Config, 0, sizeof(CONFIG_T)) ;
	readConfig(config_file_path, &Config) ;
	Log = openLog(argv[0], Config.LOG_FILE, LOG_MODE) ;
#ifdef _FOR_STAT_
	StatLog = openLog(argv[0], Config.STAT_LOG_PATH, LOG_MODE) ;
#endif
	printLog(HEAD, "=====[Program Start]=====\n") ;

	printConfig(&Config) ;

	pthread_mutex_init(&p_lock, NULL);
	thread_count = 0;

	Worker() ;

	exit_handler() ;
	return M_TRUE ;
}
Exemplo n.º 6
0
        Status addKey(const BSONObj& key, const DiskLoc& loc) {
            // inserts should be in ascending order.

            if ( key.objsize() >= TempKeyMaxSize ) {
                return Status(ErrorCodes::KeyTooLong, "key too big");
            }


            invariant(!loc.isNull());
            invariant(loc.isValid());
            invariant(!hasFieldNames(key));

            // TODO optimization: dup check can assume dup is only possible with last inserted key
            // and avoid the log(n) lookup.
            if (!_dupsAllowed && isDup(*_data, key, loc))
                return dupKeyError(key);

            _data->insert(_data->end(), IndexEntry(key.getOwned(), loc));
            *_currentKeySize += key.objsize();
            return Status::OK();
        }
Exemplo n.º 7
0
Arquivo: Main.c Projeto: k2b3d/tconsrc
int main(int argc, char *argv[])
{
	pid_t 		pid ;
	int 		stat ;
	pthread_t	pthread_ping_id;	
	int			ret ;

	isDup(argv[0]) ;

	if((pid = fork()) < 0)
		return  -1;
	else    if(pid != 0)
		exit(0);

	setsid() ;

	set_signal() ;

	if (argc > 1) {
		if (argc == 3) {
			if (strcmp(argv[1], "-f") == 0) {
				strcpy(config_file_path, argv[2]);
			}
			else    {
				printf("---------------------------------\n");
				printf("-%s [-f ConfigFilePath]\n", argv[0]);
				printf("---------------------------------\n");
				}
			}
		else    {
			printf("---------------------------------\n");
			printf("-%s [-f ConfigFilePath]\n", argv[0]);
			printf("---------------------------------\n");
		}
	}
	else
		sprintf(config_file_path, "../config/CCTVSvr.Config");

	memset(&Config, 0, sizeof(CONFIG_T)) ;
	readConfig(config_file_path, &Config) ;
	Log = openLog(argv[0], Config.LOG_FILE, LOG_MODE) ;
	printLog(HEAD, "=====[Program Start]=====\n") ;

	printConfig(&Config);

#ifdef _USEDB
	if((ret = mydbc_connect(Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_HOST, Config.DB_PORT, Config.DB_CONN_COUNT)) != DB_SUCCESS)   {
		printLog(HEAD, "DB Connection ERROR[%d]\n", ret);
		exit(0);
	}
	else    {
		printLog(HEAD, "DB Connection Success...\n");
	}
#endif

	pthread_mutex_init(&p_lock, NULL);
	thread_count = 0;

#ifdef _USEDB
	// DB PING-PONG
	if((stat = pthread_create(&pthread_ping_id, NULL, db_conn_check, (void *)NULL)) != 0) {
		printLog(HEAD, "ERR: (%s)(%d)\n", strerror(errno), errno);
		if(stat == EAGAIN) {
			printLog(HEAD, "ERR: not enough system resources to create a process for the new thread. (%d)(%d)\n", EAGAIN, stat);
		}
		exit_handler() ;
	}
#endif

	Worker();

	exit_handler() ;
	return M_TRUE ;
}
 virtual Status dupKeyCheck(OperationContext* opCtx, const BSONObj& key, const RecordId& loc) {
     invariant(!hasFieldNames(key));
     if (isDup(*_data, key, loc))
         return dupKeyError(key);
     return Status::OK();
 }
 virtual Status dupKeyCheck(OperationContext* opCtx, const BSONObj& key) {
     invariant(!hasFieldNames(key));
     if (isDup(*_data, key))
         return buildDupKeyErrorStatus(key, _collectionNamespace, _indexName, _keyPattern);
     return Status::OK();
 }