Example #1
0
unsigned int static_bitsequence::rank1(unsigned int i) {
  if(i>=len) return ones;
  if(ones==0) return -1;
  unsigned int ini = 1;
  unsigned int fin = ones;
  while(ini<fin) {
    unsigned int pos = (ini+fin)/2;
    unsigned int bp = select1(pos);
    if(bp==i) return pos;
    if(bp<i)
      ini = pos+1;
    else
      fin = pos-1;
  }
	if(select1(ini)>i) return ini-1;
	return ini;
}
size_t BitSequence::rank1(const size_t i) const {
    if (i >= length) return (size_t) -1;
    if (ones == 0) return 0;
    if (ones == length) return i + 1;
    size_t ini = 1;
    size_t fin = ones;
    while (ini < fin) {
        size_t pos = (ini + fin) / 2;
        size_t bp = select1(pos);
        if (bp == i) return pos;
        if (bp < i)
            ini = pos + 1;
        else
            fin = pos - 1;
    }
    if (select1(ini) > i) return ini - 1;
    return ini;
}
Example #3
0
int main()
{
    int n;
    sqlite3 *db;
    int ret=0;
    char str[100]="create table \
        employee(id integer primary key,name text,gender text,age integer);";
    char *ss=0;
    int ret1;
    
    ret=sqlite3_open("./tesw.db",&db);
    
    if(ret!=SQLITE_OK)
    {
        fputs(sqlite3_errmsg(db),stderr);
        fputs("\n",stderr);
        exit(1);
    }
 
    fputs("Please check :Is there  a table:employee ?\n",stdout);
    fputs("\n",stdout);
    ret=sqlite3_exec(db,"select * from employee;",NULL,NULL,NULL);
    
    if(ret)
    {
        fputs("No employee \n",stdout);
        fputs("\n",stdout);
        fputs("Create a table:employee\n",stdout);
        ss=sqlite3_mprintf("%s",str);
        ret1=sqlite3_exec(db,ss,rscallback,NULL,NULL);
        if(!ret1)fputs("finish creating\n",stdout);

        }
     fputs("yse \n",stdout);
     fputs("\n",stdout);
  
   while(1){
   fputs("1.Display all records\n",stdout);
   fputs("2.Insert Record\n",stdout);
   fputs("3.Delete Record\n",stdout);
   fputs("4.Exit\n",stdout);
   fputs("Please Select[1-4]:",stdout);
   scanf ("%d",&n);
   switch(n){
       
       case 1:select1(db);empty_cache();break;
       case 2:insert1(db);empty_cache();break;
       case 3:delete1(db);empty_cache();break;
       case 4:exit(0);
       default:return 0;
            }  
            } 

   sqlite3_close(db);

   return 0;
}
Example #4
0
File: LED.cpp Project: konao/rasp1
void LED::on(int i) {
  static int _map1[] = {3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2};
  static int _map2[] = {0x0e, 0x07, 0x0b, 0x0d, 0x0e, 0x07, 0x0b, 0x0d, 0x0e, 0x07, 0x0b, 0x0d, 0x0e, 0x07, 0x0b, 0x0d, 0x0e, 0x07, 0x0b, 0x0d, 0x0e, 0x07, 0x0b, 0x0d, 0x0e, 0x07, 0x0b, 0x0d, 0x0e, 0x07, 0x0b, 0x0d, };

  if (!_bInitOk) return;
  if (i<0 || i>31) return;

  select1(_map1[i]);
  select2(_map2[i]);
}
	uint64_t select(uint64_t i, bool b = true){

		return b ? select1(i) : select0(i);

	}
Example #6
0
LongInt
EngineBase::get_next_value(const String &seq_name)
{
    return select1(Expression(get_dialect()->select_next_value(seq_name)),
            Expression(get_dialect()->dual_name()), Expression()).as_longint();
}
size_t BitSequence::selectPrev1(const size_t i) const {
    size_t v = rank1(i);
    if (v < 2) return (size_t) -1;
    return select1(v - 1);
}
size_t BitSequence::selectNext1(const size_t i) const {
    return select1((i == 0 ? 0 : rank1(i - 1)) + 1);
}
int main()
{
    std::cout << "[moeoDetArchiveSelect] => \n";

	moeoUnboundedArchive <Solution> archive;
	Solution sol1, sol2, sol3, sol4, sol5;
	ObjectiveVector obj1, obj2, obj3, obj4, obj5;
	obj1[0]=10;
	obj1[1]=0;
	obj2[0]=9;
	obj2[1]=1;
	obj3[0]=8;
	obj3[1]=2;
	obj4[0]=7;
	obj4[1]=3;
	obj5[0]=6;
	obj5[1]=4;

	sol1.objectiveVector(obj1);
	sol2.objectiveVector(obj2);
	sol3.objectiveVector(obj3);
	sol4.objectiveVector(obj4);
	sol5.objectiveVector(obj5);

	archive(sol1);
	archive(sol2);
	archive(sol3);
	archive(sol4);
	archive(sol5);
	assert(archive.size() == 5);

	//archive.printOn(std::cout);

	eoPop <Solution> source, dest;

	// test with max > archive size
	moeoDetArchiveSelect <Solution> select1(archive, 10);
	select1(source, dest);
	for(unsigned int i=0; i< archive.size(); i++){
		assert(dest[i].objectiveVector()[0]==archive[i].objectiveVector()[0]);
		assert(dest[i].objectiveVector()[1]==archive[i].objectiveVector()[1]);
	}

	//test with a max < archive size
	dest.resize(0);
	moeoDetArchiveSelect <Solution> select2(archive, 3);
	select2(source, dest);
	assert(dest.size()==3);

	//test with archive size < min
	dest.resize(0);
	moeoDetArchiveSelect <Solution> select3(archive, 100, 10);
	select3(source, dest);
	for(int i=0; i< 10; i++){
		assert(dest[i].objectiveVector()[0]==archive[i%archive.size()].objectiveVector()[0]);
		assert(dest[i].objectiveVector()[1]==archive[i%archive.size()].objectiveVector()[1]);
	}

	//test with bad value
	dest.resize(0);
	moeoDetArchiveSelect <Solution> select4(archive, 10, 11);
	select4(source, dest);
	assert(dest.size()==0);

	std::cout << " OK\n";
    return EXIT_SUCCESS;
}
Example #10
0
 /**
  * @brief Returns the position of the x-th occurrence of `b`
  *
  * @param[in] x Rank number of b-bits
  * @param[in] b Boolean value that indicates bit type.(true = 1, false = 0)
  *
  * @return Index of x-th 0
  */
 FORCE_INLINE  uint64_t select(uint64_t x, bool b = true) const {
     return b ? select1(x) : select0(x);
 }