コード例 #1
0
ファイル: mrzzn3.c プロジェクト: FlexCOS/code
void zzn3_div2(_MIPD_ zzn3 *w)
{
#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif
    if (mr_mip->ERNUM) return;
    MR_IN(188)
    copy(w->a,mr_mip->w1);
    if (remain(_MIPP_ mr_mip->w1,2)!=0)
        add(_MIPP_ mr_mip->w1,mr_mip->modulus,mr_mip->w1);
    subdiv(_MIPP_ mr_mip->w1,2,mr_mip->w1);
    copy(mr_mip->w1,w->a);

    copy(w->b,mr_mip->w1);
    if (remain(_MIPP_ mr_mip->w1,2)!=0)
        add(_MIPP_ mr_mip->w1,mr_mip->modulus,mr_mip->w1);
    subdiv(_MIPP_ mr_mip->w1,2,mr_mip->w1);
    copy(mr_mip->w1,w->b);

    copy(w->c,mr_mip->w1);
    if (remain(_MIPP_ mr_mip->w1,2)!=0)
        add(_MIPP_ mr_mip->w1,mr_mip->modulus,mr_mip->w1);
    subdiv(_MIPP_ mr_mip->w1,2,mr_mip->w1);
    copy(mr_mip->w1,w->c);

    MR_OUT
}
コード例 #2
0
ファイル: QSIEVE.C プロジェクト: karllen/Windows_Program
int knuth(int mm,int *epr,big N,big D)
{ /* Input number to be factored N and find best multiplier k  *
   * for use over a factor base epr[] of size mm.  Set D=k.N.  */
    double dp,fks,top;
    BOOL found;
    int i,j,bk,nk,kk,r,p;
    static int K[]={0,1,2,3,5,6,7,10,11,13,14,15,17,0};
    top=(-10.0e0);
    found=FALSE;
    nk=0;
    bk=0;
    epr[0]=1;
    epr[1]=2;
    do
    { /* search for best Knuth-Schroepel multiplier */
        kk=K[++nk];
        if (kk==0)
        { /* finished */
            kk=K[bk];
            found=TRUE;
        }
        premult(N,kk,D);
        fks=log(2.0e0)/(2.0e0);
        r=remain(D,8);
        if (r==1) fks*=(4.0e0);
        if (r==5) fks*=(2.0e0);
        fks-=log((double)kk)/(2.0e0);
        i=0;
        j=1;
        while (j<mm)
        { /* select small primes */
            p=mip->PRIMES[++i];
            r=remain(D,p);
            if (spmd(r,(p-1)/2,p)<=1)
            { /* use only if Jacobi symbol = 0 or 1 */
                epr[++j]=p;
                dp=(double)p;
                if (kk%p==0) fks+=log(dp)/dp;
                else         fks+=2*log(dp)/(dp-1.0e0);
            }
        }
        if (fks>top)
        { /* find biggest fks */
            top=fks;
            bk=nk;
        }
    } while (!found);
    return kk;
}
コード例 #3
0
ファイル: variable_pool.hpp プロジェクト: mutouyun/capo
 void* alloc(size_t size)
 {
     if (remain() < size)
     {
         return alloc_new_chunk(size);
     }
     char* buff = tail_ - size;
     if (buff < head_)
     {
         return alloc_new_chunk(size);
     }
     tail_ = buff;
     chain()->free_ = remain();
     return tail_;
 }
コード例 #4
0
ファイル: mrxgcd.c プロジェクト: BingyZhang/CommutEnc
int invmodp(_MIPD_ big a,big p,big z)
{
#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif
    big u,v,x1,x2;

    MR_IN(213);

    u=mr_mip->w1; v=mr_mip->w2; x1=mr_mip->w3; x2=mr_mip->w4;
    copy(a,u);    
    copy(p,v);    
    convert(_MIPP_ 1,x1); 
    zero(x2);      
   
    while (size(u)!=1 && size(v)!=1)
    {
        while (remain(_MIPP_ u,2)==0)
        {
            subdiv(_MIPP_ u,2,u);
            if (remain(_MIPP_ x1,2)!=0) add(_MIPP_ x1,p,x1);
            subdiv(_MIPP_ x1,2,x1);
        }
        while (remain(_MIPP_ v,2)==0)
        {
            subdiv(_MIPP_ v,2,v);
            if (remain(_MIPP_ x2,2)!=0) add(_MIPP_ x2,p,x2);
            subdiv(_MIPP_ x2,2,x2);
        }
        if (mr_compare(u,v)>=0)
        {
            mr_psub(_MIPP_ u,v,u);
            subtract(_MIPP_ x1,x2,x1);
        }
        else
        {
            mr_psub(_MIPP_ v,u,v);
            subtract(_MIPP_ x2,x1,x2);
        }
    }
    if (size(u)==1) copy(x1,z);
    else            copy(x2,z);

    if (size(z)<0) add(_MIPP_ z,p,z);

    MR_OUT
    return 1; /* note - no checking that gcd=1 */
}
コード例 #5
0
void Dijkstra(int p, int w[N][N], int d[N])
{
  int i, u, x, k;
  int j, m;
  struct vertices U, V;

  set_vertices(&V, FALSE);
  set_vertices(&U, TRUE);
  for (i = 0; i < N; i++) {
    d[i] = M;
  }
  d[p] = 0;

  printf("(3)\n");
  printf("   (a)\n");

  while (remain(&U)) {
    u = select_min(d, &U); /* (ア) */
    /* (3)(a) */
    printf("       u == %d\n", u);

    add_vertex(u, &V);
    remove_vertex(u, &U);
    for (x = 0; x < N; x++) {
      if (w[u][x] < M && member(x, &U)) {
        k = d[u] + w[u][x];
        if (k < d[x]) {
          d[x] = k;
        }
      }
    }
  }
}
コード例 #6
0
ファイル: variable_pool.hpp プロジェクト: mutouyun/capo
    void* alloc_new_chunk(size_t size, size_t alignment)
    {
        size_t offset = alignment - 1;
        size_t adjust_size = offset + size;

        head_t* p = alloc_head(HeadSize + adjust_size);
        if (p == nullptr) return nullptr;
        head_t* list = chain();
        if (adjust_size > BufferSize && list != nullptr)
        {
            p->next_ = list->next_;
            list->next_ = p;
            char* head = reinterpret_cast<char*>(p + 1);
            char* tail = adjust_alignment(head + p->free_ - size, offset);
            p->free_ = tail - head;
            return tail;
        }
        else
        {
            p->next_ = list;
            head_ = reinterpret_cast<char*>(p + 1);
            tail_ = adjust_alignment(head_ + p->free_ - size, offset);
            p->free_ = remain();
            return tail_;
        }
    }
コード例 #7
0
int remain(int n, int k)
{
    if(n==1)
        return 1;
    else
        return ((remain(n-1,k)+k-1)%n)+1;
}
コード例 #8
0
void HashtableTextDump::skip_past(char c) {
  for (;;) {
    corrupted_if(remain() < 1);
    if (*_p++ == c) {
      return;
    }
  }
}
コード例 #9
0
ファイル: File_Extractor.cpp プロジェクト: Annovae/desmume
blargg_err_t File_Extractor::extract_v( void* out, int count )
{
	void const* p;
	RETURN_ERR( data( &p ) );
	memcpy( out, STATIC_CAST(char const*,p) + (size() - remain()), count );
	
	return blargg_ok;
}
コード例 #10
0
// Insert multiple records and create a random iterator for the record store
TEST(RecordStoreTestHarness, GetRandomIteratorNonEmpty) {
    unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
    unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore());

    {
        unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
        ASSERT_EQUALS(0, rs->numRecords(opCtx.get()));
    }

    const unsigned nToInsert =
        5000;  // should be non-trivial amount, so we get multiple btree levels
    RecordId locs[nToInsert];
    for (unsigned i = 0; i < nToInsert; i++) {
        unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
        {
            stringstream ss;
            ss << "record " << i;
            string data = ss.str();

            WriteUnitOfWork uow(opCtx.get());
            StatusWith<RecordId> res =
                rs->insertRecord(opCtx.get(), data.c_str(), data.size() + 1, false);
            ASSERT_OK(res.getStatus());
            locs[i] = res.getValue();
            uow.commit();
        }
    }

    {
        unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
        ASSERT_EQUALS(nToInsert, rs->numRecords(opCtx.get()));
    }

    set<RecordId> remain(locs, locs + nToInsert);
    {
        unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
        auto cursor = rs->getRandomCursor(opCtx.get());
        // returns NULL if getRandomCursor is not supported
        if (!cursor) {
            return;
        }

        // Iterate documents and mark those visited, but let at least one remain
        for (unsigned i = 0; i < nToInsert - 1; i++) {
            // Get a new cursor once in a while, shouldn't affect things
            if (i % (nToInsert / 8) == 0) {
                cursor = rs->getRandomCursor(opCtx.get());
            }
            remain.erase(cursor->next()->id);  // can happen more than once per doc
        }
        ASSERT(!remain.empty());
        ASSERT(cursor->next());

        // We should have at least visited a quarter of the items if we're any random at all
        // The expected fraction of visited records is 62.3%.
        ASSERT_LT(remain.size(), nToInsert * 3 / 4);
    }
}
コード例 #11
0
void HashtableTextDump::check_version(const char* ver) {
  int len = (int)strlen(ver);
  corrupted_if(remain() < len);
  if (strncmp(_p, ver, len) != 0) {
    quit("wrong version of hashtable dump file", _filename);
  }
  _p += len;
  skip_newline();
}
コード例 #12
0
ファイル: EdMemReader.cpp プロジェクト: netmindms/ednio
size_t EdMemReader::read(char* buf, size_t bufsize)
{
	size_t rcnt = min(bufsize, remain());
	if (rcnt > 0)
	{
		memcpy(buf, mBuf + mReadCnt, rcnt);
		mReadCnt += rcnt;
	}
	return rcnt;
}
コード例 #13
0
ファイル: Data_Reader.cpp プロジェクト: STJr/SRB2
long Mem_File_Reader::read_avail( void* p, long s )
{
	long r = remain();
	s = max( 0l, s );
	if ( s > r )
		s = r;
	memcpy( p, begin + pos, s );
	pos += s;
	return s;
}
コード例 #14
0
ファイル: memory.cpp プロジェクト: CarlosX/DarkEmu
void SimpleBuffer::seek(int amt, bool current){
	if(current){
		if(amt > 0){
			if((uint)amt > remain())
				_cur = _length;
			else
				_cur += (uint)amt;
		}else{
			amt = -1 * amt;
			if((uint)amt > _cur) _cur = 0;
			else _cur += (uint)amt;
		}
	}else{
		if(amt <= 0) return;

		if((uint)amt > remain()) _cur = _length;
		else
			_cur += (uint)amt;
	}
}
コード例 #15
0
ファイル: Nes_File.cpp プロジェクト: Sir-Ironic/QuickNES_Core
const char * Nes_File_Reader::read_block_data( void* p, long s )
{
	long extra = remain();
	if ( s > extra )
		s = extra;
	extra -= s;
	RETURN_ERR( read( p, s ) );
	if ( extra )
		RETURN_ERR( skip( extra ) );
	return 0;
}
コード例 #16
0
sp<AaptFile> AaptAssets::addFile(
        const String8& filePath, const AaptGroupEntry& entry,
        const String8& srcDir, sp<AaptGroup>* outGroup,
        const String8& resType)
{
    sp<AaptDir> dir = this;
    sp<AaptGroup> group;
    sp<AaptFile> file;
    String8 root, remain(filePath), partialPath;
    while (remain.length() > 0) {
        root = remain.walkPath(&remain);
        partialPath.appendPath(root);

        const String8 rootStr(root);

        if (remain.length() == 0) {
            ssize_t i = dir->getFiles().indexOfKey(rootStr);
            if (i >= 0) {
                group = dir->getFiles().valueAt(i);
            } else {
                group = new AaptGroup(rootStr, filePath);
                status_t res = dir->addFile(rootStr, group);
                if (res != NO_ERROR) {
                    return NULL;
                }
            }
            file = new AaptFile(srcDir.appendPathCopy(filePath), entry, resType);
            status_t res = group->addFile(file);
            if (res != NO_ERROR) {
                return NULL;
            }
            break;

        } else {
            ssize_t i = dir->getDirs().indexOfKey(rootStr);
            if (i >= 0) {
                dir = dir->getDirs().valueAt(i);
            } else {
                sp<AaptDir> subdir = new AaptDir(rootStr, partialPath);
                status_t res = dir->addDir(rootStr, subdir);
                if (res != NO_ERROR) {
                    return NULL;
                }
                dir = subdir;
            }
        }
    }

    mGroupEntries.add(entry);
    if (outGroup) *outGroup = group;
    return file;
}
コード例 #17
0
    // Insert multiple records and create an iterator for repairing the record store,
    // even though the it has not been corrupted.
    TEST( RecordStoreTestHarness, GetIteratorForRepairNonEmpty ) {
        scoped_ptr<HarnessHelper> harnessHelper( newHarnessHelper() );
        scoped_ptr<RecordStore> rs( harnessHelper->newNonCappedRecordStore() );

        {
            scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
            ASSERT_EQUALS( 0, rs->numRecords( opCtx.get() ) );
        }

        const int nToInsert = 10;
        DiskLoc locs[nToInsert];
        for ( int i = 0; i < nToInsert; i++ ) {
            scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
            {
                stringstream ss;
                ss << "record " << i;
                string data = ss.str();

                WriteUnitOfWork uow( opCtx.get() );
                StatusWith<DiskLoc> res = rs->insertRecord( opCtx.get(),
                                                            data.c_str(),
                                                            data.size() + 1,
                                                            false );
                ASSERT_OK( res.getStatus() );
                locs[i] = res.getValue();
                uow.commit();
            }
        }

        {
            scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
            ASSERT_EQUALS( nToInsert, rs->numRecords( opCtx.get() ) );
        }

        set<DiskLoc> remain( locs, locs + nToInsert );
        {
            scoped_ptr<OperationContext> opCtx( harnessHelper->newOperationContext() );
            RecordIterator *it = rs->getIteratorForRepair( opCtx.get() );

            while ( !it->isEOF() ) {
                DiskLoc loc = it->curr();
                ASSERT( 1 == remain.erase( loc ) );
                ASSERT_EQUALS( loc, it->getNext() );
            }
            ASSERT( remain.empty() );

            ASSERT_EQUALS( DiskLoc(), it->curr() );
            ASSERT_EQUALS( DiskLoc(), it->getNext() );
            ASSERT( it->isEOF() );
            ASSERT_EQUALS( DiskLoc(), it->curr() );
        }
    }
コード例 #18
0
ファイル: userwindow.cpp プロジェクト: yangzw/library-with-Qt
void userWindow::createdelwindow()
{
	deleteAccount = new QDialog;
	QLabel *remind = new QLabel(tr("<h2>Are  you sure </h1>\n<h2>you want to delete your account?</h1>"),deleteAccount);
	QPushButton *oktodelet = new QPushButton(tr("Delete"),deleteAccount);
	QPushButton *canceldel = new QPushButton(tr("Cancel"),deleteAccount);
	QGridLayout *dellayout = new QGridLayout;
	dellayout->addWidget(remind,0,0);
	dellayout->addWidget(oktodelet,1,0);
	dellayout->addWidget(canceldel,1,2);
	deleteAccount->setLayout(dellayout);
	connect(oktodelet,SIGNAL(clicked()),this,SLOT(delusr()));
	connect(canceldel,SIGNAL(clicked()),this,SLOT(remain()));
}
コード例 #19
0
static void MSFindSymbols(MSImageRef image, size_t count, const char *names[], void *values[]) {
    MSSymbolData items[count];

    for (size_t index(0); index != count; ++index) {
        MSSymbolData &item(items[index]);

        item.name_ = names[index];
        item.type_ = 0;
        item.sect_ = 0;
        item.desc_ = 0;
        item.value_ = 0;
    }

    if (image != NULL)
        MSMachONameList_(image, items, count);
    else {
        size_t remain(count);

        for (uint32_t image(0), images(_dyld_image_count()); image != images; ++image) {
            //fprintf(stderr, ":: %s\n", _dyld_get_image_name(image));

            ssize_t result(MSMachONameList_(_dyld_get_image_header(image), items, count));
            if (result == -1)
                continue;

            // XXX: maybe avoid this happening at all? a flag to NSMachONameList_?
            for (size_t index(0); index != count; ++index) {
                MSSymbolData &item(items[index]);
                if (item.name_ == NULL && item.value_ == 0) {
                    ++result;
                    item.name_ = names[index];
                }
            }

            remain -= count - result;
            if (remain == 0)
                break;
        }
    }

    for (size_t index(0); index != count; ++index) {
        MSSymbolData &item(items[index]);
        uintptr_t value(item.value_);
#ifdef __arm__
        if ((item.desc_ & N_ARM_THUMB_DEF) != 0)
            value |= 0x00000001;
#endif
        values[index] = reinterpret_cast<void *>(value);
    }
}
コード例 #20
0
ファイル: Q18_08.cpp プロジェクト: lbl1985/TestCPPCode
 std::vector<int> search(std::string s){
     if (s.length() == 0) {
         return indexes;
     }else{
         char first = s.at(0);
         if (children.find(first) != children.end()) {
             std::string remain(s.substr(1));
             return children[first]->search(remain);
         }
     }
     
     std::vector<int> tmp;
     return tmp;
 }
コード例 #21
0
// Insert multiple records and create an iterator for repairing the record store,
// even though the it has not been corrupted.
TEST(RecordStoreTestHarness, GetIteratorForRepairNonEmpty) {
    unique_ptr<HarnessHelper> harnessHelper(newHarnessHelper());
    unique_ptr<RecordStore> rs(harnessHelper->newNonCappedRecordStore());

    {
        unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
        ASSERT_EQUALS(0, rs->numRecords(opCtx.get()));
    }

    const int nToInsert = 10;
    RecordId locs[nToInsert];
    for (int i = 0; i < nToInsert; i++) {
        unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
        {
            stringstream ss;
            ss << "record " << i;
            string data = ss.str();

            WriteUnitOfWork uow(opCtx.get());
            StatusWith<RecordId> res =
                rs->insertRecord(opCtx.get(), data.c_str(), data.size() + 1, false);
            ASSERT_OK(res.getStatus());
            locs[i] = res.getValue();
            uow.commit();
        }
    }

    {
        unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
        ASSERT_EQUALS(nToInsert, rs->numRecords(opCtx.get()));
    }

    set<RecordId> remain(locs, locs + nToInsert);
    {
        unique_ptr<OperationContext> opCtx(harnessHelper->newOperationContext());
        auto cursor = rs->getCursorForRepair(opCtx.get());
        // returns NULL if getCursorForRepair is not supported
        if (!cursor) {
            return;
        }

        while (auto record = cursor->next()) {
            remain.erase(record->id);  // can happen more than once per doc
        }
        ASSERT(remain.empty());

        ASSERT(!cursor->next());
    }
}
コード例 #22
0
ファイル: 5_22.c プロジェクト: tcarrio/c-4
int main(){
	printf("Enter an integer\n");
	scanf("%d",&user_a);
	printf("Enter another integer\n");
	scanf("%d",&user_b);
	char* user_a_str;
	sprintf(user_a_str,"%d",user_a);
	printf("The integer quotient of your integers is %d\n",divide(user_a,user_b));
	printf("The integer remainder of your integer is %d\n",remain(user_a,user_b));
	printf("Separating each number in the first entry:");
	for(int x=0; x<sizeof(user_a_str); x++){
		printf("  %c",user_a_str[x]);
	}

}
コード例 #23
0
ファイル: variable_pool.hpp プロジェクト: mutouyun/capo
    void* alloc(size_t size, size_t alignment)
    {
        CAPO_ASSERT_(!(alignment & (alignment - 1)))(alignment);

        if (remain() < size)
        {
            return alloc_new_chunk(size, alignment);
        }

        char* buff = tail_ - size;
        size_t x = reinterpret_cast<size_t>(buff);
        x &= ~(x - 1); // calculate the alignment of buffer
        if (x < alignment)
        {
            buff = adjust_alignment(buff, alignment - 1);
            if (buff < head_)
            {
                return alloc_new_chunk(size, alignment);
            }
        }
        tail_ = buff;
        chain()->free_ = remain();
        return tail_;
    }
コード例 #24
0
ファイル: Q18_08.cpp プロジェクト: lbl1985/TestCPPCode
 void insertString(std::string s, int index){
     indexes.push_back(index);
     if (s.size()>0) {
         value = s.at(0);
         std::shared_ptr<SuffixTreeNode> child;
         if (children.find(value) != children.end()) {
             child = children[value];
         }else{
             child.reset(new SuffixTreeNode());
             children[value] = child;
         }
         std::string remain(s.substr(1));
         child->insertString(remain, index);
     }
 }
コード例 #25
0
int main()
{
    int n,k,t,i;

    scanf("%d",&t);

    for(i=1;i<=t;i++)
    {
        scanf("%d%d",&n,&k);
        printf("Case %d: %d\n",i,remain(n,k));
    }

    return 0;

}
コード例 #26
0
ファイル: PySparseTensor.hpp プロジェクト: ARK1988/nupic
  PySparseTensor getComplementBounds(const PyTensorIndex &dims) const
  {
    PyTensorIndex process(tensor_.getBounds());
    nta::UInt32 n = dims.size();
    for(nta::UInt32 i=0; i<n; ++i)
      process[dims[i]] = 0;

    n = process.size();
    PyTensorIndex remain(n - dims.size(), (const nta::UInt32 *) 0);
    nta::UInt32 cur = 0;
    for(nta::UInt32 i=0; i<n; ++i) {
      nta::UInt32 keep = process[i];
      if(keep) remain[cur++] = keep;
    }
    return remain;
  }
コード例 #27
0
const char * Data_Reader::skip( int n )
{
	if ( n < 0 )
		return blargg_err_caller;
	
	if ( n <= 0 )
		return 0;
	
	if ( n > remain() )
		return blargg_err_file_eof;
	
	const char * err = skip_v( n );
	if ( !err )
		remain_ -= n;
	
	return err;
}
コード例 #28
0
const char * Data_Reader::read( void* p, int n )
{
	if ( n < 0 )
		return blargg_err_caller;
	
	if ( n <= 0 )
		return 0;
	
	if ( n > remain() )
		return blargg_err_file_eof;
	
	const char * err = read_v( p, n );
	if ( !err )
		remain_ -= n;
	
	return err;
}
コード例 #29
0
ファイル: zzn.cpp プロジェクト: JacobBarthelmeh/supercop
ZZn& ZZn::operator/=(int i)
{
 if (i==1) return *this; 
 if (i==2)
 { // make a special effort... modulus is odd
    copy(fn,get_mip()->w1);
    if (remain(get_mip()->w1,2)!=0)
        add(get_mip()->w1,get_mip()->modulus,get_mip()->w1);
    subdiv(get_mip()->w1,2,get_mip()->w1);
    copy(get_mip()->w1,fn);

    return *this;
 }
 ZZn x=i;
 nres_moddiv(fn,x.fn,fn);
 return *this;
}
コード例 #30
0
ファイル: mrjack.c プロジェクト: FlexCOS/code
int jack(_MIPD_ big a,big n)
{ /* find jacobi symbol (a/n), for positive odd n */
    big w;
    int nm8,onm8,t;
#ifdef MR_OS_THREADS
    miracl *mr_mip=get_mip();
#endif
    if (mr_mip->ERNUM || size(a)==0 || size(n) <1) return 0;
    MR_IN(3)

    t=1;
    copy(n,mr_mip->w2);
    nm8=remain(_MIPP_ mr_mip->w2,8);
    if (nm8%2==0) 
    {
        MR_OUT
        return 0;
    }