예제 #1
0
void interactive()
{
	HashTable* ht = makeTable(22);
	for (unsigned i = 0; i < 27; ++i) {
		ht = insertTable(ht, namen[i], rand() % 100);
	}
	printHashTable(ht);
	while (1) {
		unsigned i;
		printf( "Insert (2) or search (1) or delete (0)? " );
		scanf(  "%u", &i );
		if (i == 2) {
			printf( "Name: " );
			char* name = getline();
			unsigned telNr;
			printf( "Telephone-Nr.: " );
			scanf("%u", &telNr);
			ht = insertTable(ht, name, telNr);
			printHashTable(ht);
		} else if (i == 1) {
			printf( "Name: " );
			char* name = getline();
			unsigned* telNr = searchTable(ht, name);
			printf( "Telephone-Nr.: %u\n", *telNr );
		} else {
			printf( "Name: " );
			char* name = getline();
			deleteTable(ht, name);
			printHashTable(ht);
		}
	}
}
예제 #2
0
        TEST_F(DBTableTest, find_data_condition) {
            std::string tableName = "testTable";
            std::string fieldName = "fieldName";
            createTable(tableName, {"a integer, b integer"});
            insertTable(tableName, "1, 3");
            insertTable(tableName, "10, 30");
            insertTable(tableName, "100, 300");

            dbTable = std::make_shared<DBTable>(tableName);

            auto row = dbTable->find("a=10");

            ASSERT_THAT(row->getValue("b"), IsAnyInteger(30));
        }
예제 #3
0
bool DbNote::saveCategory(Category & cat , save_t sav)
{
    if(sav == append_entr)
    {
        if( existCategory(cat))
        {
            std::cout << "Category exists! Can't save this categeory !" << std::endl;
            return false;
        }
        if( ! insertTable( cat ) )
            return false;
        else
            return true;
    }
    else if( sav == write_entr )
    {
        if( ! existCategory(cat) )
        {
            std::cout << "Category doesn't exists! Can't override this categeory !" << std::endl;
            return false;
        }
        if( ! updateRow( cat ) )
        {
            return false;
        }
        else
            return true;
    }
    return false;
}
예제 #4
0
파일: parser.c 프로젝트: shenchi/mycc
ident_t createid(idtype_t type, vartype_t subtype, char *id, symbol_t val){
    symtab_t tab = global;
    ident_t nid;

    if(context){
        tab = context->local;
        if(findTable(tab, id)){
            msg(DEBUG, "identifier has been defined", line);
			exit(0);
        }
    }

    if(type==CONSTANT || type==LIT){
        if(!typecheck(subtype, val->type)){
            msg(ERR, "type mismatch", line);
			ERROR_STATUS = 1;
        }
    }

    nid = createIdent();
    nid->type = type;
    if(type!=LABEL)
        nid->subtype = subtype;
    nid->name = id;
    if(val)nid->data = val->value;
    nid->extra = 0;
    if(insertTable(tab, nid)){
        msg(DEBUG, "failed to insert identifier", line);
		exit(0);
    }
	if(tab == global) nid->loc = LOC_GLOBAL;
	else nid->loc = LOC_LOCAL;
    return nid;
}
예제 #5
0
        TEST_F(DBTableTest, find_data_integer) {
            std::string fieldName = "fieldName";
            createTable(tableName, {"a integer"});
            insertTable(tableName, "3");

            dbTable = std::make_shared<DBTable>(tableName);

            auto row = dbTable->find("");

            ASSERT_THAT(row->getValue("a"), IsAnyInteger(3));
        }
예제 #6
0
        TEST_F(DBTableTest, find_data_string) {
            std::string fieldName = "fieldName";
            createTable(tableName, {"a text"});
            insertTable(tableName, "'text-text'");

            dbTable = std::make_shared<DBTable>(tableName);

            auto row = dbTable->find("");

            ASSERT_THAT(row->getValue("a"), IsAnyString("text-text"));
        }
예제 #7
0
        TEST_F(DBTableTest, find_data_bool) {
            std::string fieldName = "fieldName";
            createTable(tableName, {"a boolean"});
            insertTable(tableName, "'on'");

            dbTable = std::make_shared<DBTable>(tableName);

            auto row = dbTable->find("");

            ASSERT_THAT(row->getValue("a"), IsAnyBool(true));
        }
예제 #8
0
        TEST_F(DBTableTest, find_data_float) {
            std::string fieldName = "fieldName";
            createTable(tableName, {"a real"});
            insertTable(tableName, "3.6");

            dbTable = std::make_shared<DBTable>(tableName);

            auto row = dbTable->find("");

            ASSERT_THAT(row->getValue("a"), IsAnyDouble(3.6));
        }
예제 #9
0
        TEST_F(DBTableTest, next_row) {

            std::string fieldName = "fieldName";
            createTable(tableName, {"a integer, b integer"});
            insertTable(tableName, "1, 3");
            insertTable(tableName, "10, 30");
            insertTable(tableName, "100, 300");

            dbTable = std::make_shared<DBTable>(tableName);

            auto row1 = dbTable->find("");
            ASSERT_THAT(row1->getValue("b"), IsAnyInteger(3));
            auto row2 = dbTable->nextRow();
            ASSERT_THAT((bool) row2, true);
            ASSERT_THAT(row2->getValue("b"), IsAnyInteger(30));
            auto row3 = dbTable->nextRow();
            ASSERT_THAT((bool) row3, true);
            ASSERT_THAT(row3->getValue("b"), IsAnyInteger(300));
            auto row4 = dbTable->nextRow();
            ASSERT_THAT((bool) row4, false);
        }
예제 #10
0
        TEST_F(DBTableTest, find_data_timestamp) {
            std::string fieldName = "fieldName";
            createTable(tableName, {"a timestamp"});
            insertTable(tableName, "'2015-01-25 12:11:54.88'");
            ptime expectedTime(date(2015, 1, 25), time_duration(12, 11, 54, 880000));

            dbTable = std::make_shared<DBTable>(tableName);

            auto row = dbTable->find("");

            ASSERT_THAT(row->getValue("a"), IsAnyPosixTime(expectedTime));

        }
예제 #11
0
bool DbNote::saveEntry(Note & note, save_t sav)
{
    Category cat;
    cat.setKatKey(note.getKatKey());

    if (! existCategory(cat))
    {
        cout << "Category doesn't exists" << endl;
        return false;
    }
    if (note.getNoteRef() != 0)
    {
        Note ref_note;
        ref_note.setNoteKey(note.getNoteRef());
        if( ! existNote(ref_note) )
        {
            std::cout << "Can't find given note reference" << std::endl;
            return false;
        }
    }
    if (sav == append_entr)
    {
        if (note.getNoteKey() != 0)
        {
            cout << "Note entry exists" << endl;
            return false;
        }
        if (!insertTable(note))
        {
            cerr << "Insert notice failed" << endl;
            return false;
        }
    }
    else if (sav == write_entr)
    {
        if ( ! existNote(note) )
        {
            cout << "Can't override notice cause of the notice doesn't exists"
                 << endl;
            return false;
        }
        if (!updateRow( note))
        {
            cerr << "Update the notice failed" << endl;
            return false;
        }
    }
    return true;
}
예제 #12
0
void MarkovPrefetcher::access(MemRequest *mreq)
{
  uint32_t paddr = mreq->getPAddr() & defaultMask;
  
  if (mreq->getMemOperation() == MemRead
      || mreq->getMemOperation() == MemReadW) {
    read(mreq);
    insertTable(paddr);
  }else{
      bLine *l = buff->readLine(paddr);
      if(l)
	l->invalidate();
    mreq->goDown(0, lowerLevel[0]);
  }
  accesses.inc();
}
예제 #13
0
파일: parser.c 프로젝트: shenchi/mycc
ident_t getLiteral(symtab_t tab, symbol_t s){
    symtab_t p = tab->next, q;
    ident_t id;
    while(p){
        id = p->entry;
        if(id->type == LIT && id->subtype == translate(s->type) && id->data == s->value){
            return id;
        }
        q = p;
        p = p->next;
    }
    id = createIdent();
    id->type=LIT;
    id->subtype = translate(s->type);
    id->data = s->value;
    id->name = ccgenname(litnum++, '_');
	id->loc = LOC_GLOBAL;
    insertTable(tab, id);
    return id;
}
예제 #14
0
void QFPRDRTable::registerToMenu(QMenu* menu) {
    QAction* insertRDTableFileAct = new QFActionWithNoMenuRole(QIcon(":/table/table_open.png"), tr("Table from File [readonly]"), parentWidget);
    insertRDTableFileAct->setStatusTip(tr("Insert a new table raw data item from a specified file"));
    connect(insertRDTableFileAct, SIGNAL(triggered()), this, SLOT(insertTableFile()));

    QAction* insertRDTableFileEditableAct = new QFActionWithNoMenuRole(QIcon(":/table/table_open.png"), tr("Import Table from File [editable]"), parentWidget);
    insertRDTableFileEditableAct->setStatusTip(tr("Insert a new table raw data item from a specified file"));
    connect(insertRDTableFileEditableAct, SIGNAL(triggered()), this, SLOT(insertTableFileEdit()));

    QAction* insertRDTableAct = new QFActionWithNoMenuRole(QIcon(":/table/table_insert.png"), tr("Editable Table"), parentWidget);
    insertRDTableAct->setStatusTip(tr("Insert a new table raw data item, which may be edited in QuickFit 3.0 and is not connected to a file."));
    connect(insertRDTableAct, SIGNAL(triggered()), this, SLOT(insertTable()));

    QMenu* m=new QMenu(tr("&Table"), menu);
    m->setIcon(QIcon(":/table/projecttree_tablefile.png"));
    m->addAction(insertRDTableAct);
    m->addAction(insertRDTableFileAct);
    m->addAction(insertRDTableFileEditableAct);
    menu->addMenu(m);
}
예제 #15
0
bool DbNote::createDB()
{
    sqlite3_stmt *statement;
    string stmnt = "CREATE TABLE KatTable(	KatKey INTEGER PRIMARY KEY\
										autoincrement,KatDesc TEXT);";
    if (!openDB())
    {
        throw SQLError("Can't open the DB-Connection");
        return false;
    }
    int req = sqlite3_prepare_v2(db, stmnt.c_str(), -1, &statement, 0);
    if (req != SQLITE_OK)
    {
        throw SQLError("Preparing Select-Statement failed in existCategory()");
        return false;
    }
    req = sqlite3_step(statement);
    sqlite3_finalize(statement);

    stmnt = "CREATE TABLE NoteTable( NoteKey INTEGER PRIMARY KEY autoincrement,\
						date TEXT,\
						NoteText TEXT,\
						NoteTitle TEXT,\
						KatKey INTEGER,\
						NoteRef INTEGER,\
						FOREIGN KEY (KatKey) REFERENCES KatTable(KatKey));";
    req = sqlite3_prepare_v2(db, stmnt.c_str(), -1, &statement, 0);
    if (req != SQLITE_OK)
    {
        throw SQLError("Preparing Select-Statement failed in existCategory()");
        return false;
    }
    req = sqlite3_step(statement);
    sqlite3_finalize(statement);
    sqlite3_close(db);
    Category c;
    c.setKatDesc("notice (default)");
    insertTable(c);
    return true;
}
예제 #16
0
void MarkovPrefetcher::TESTinsertTable(PAddr addr){
  
  TESTdata[0] = 10000;
  TESTdata[1] = 20000;
  TESTdata[2] = 30000;
  TESTdata[3] = 40000;
  TESTdata[4] = 30000;
  TESTdata[5] = 10000;
  TESTdata[6] = 30000;
  TESTdata[7] = 40000;
  TESTdata[8] = 20000;
  TESTdata[9] = 30000;
  TESTdata[10] = 10000;

  for(int32_t i = 0; i < 11; i++) {
    PAddr d = TESTdata[i];
    LOG("Addr %d", d);    
    insertTable(d);
  }

  exit(1);
}
예제 #17
0
/* Desc of nulltest table timestampNull = true

| Field | Type          | Null | Key | Default              | Extra
+-------+---------------+------+-----+----------------------+-------------------
| id    | int(11)       | NO   | PRI | NULL                 |
| fd1   | int(11)       | YES  | UNI | NULL                 |
| fd2   | int(11)       | YES  |     | NULL                 |
| fd3   | int(11)       | YES  |     | NULL                 |
| fd4   | int(11)       | YES  |     | NULL                 |
| fd5   | int(11)       | YES  |     | -1                   |
| fd6   | varchar(16)   | YES  |     | NULL                 |
| fd7   | varbinary(50) | YES  |     | NULL                 |
| fd8   | timestamp(6)  | YES  |     | NULL                 |
| fd9   | datetime(6)   | YES  |     | NULL                 |
| fd10  | timestamp(6)  | YES  |     | CURRENT_TIMESTAMP(6) | on update CURRENT_TIMESTAMP(6)
| fd11  | datetime(6)   | YES  |     | NULL                 |
+-------+---------------+------+-----+----------------------+-------------------

CREATE TABLE `nulltest` (`id` INT NOT NULL ,`fd1` INT NULL DEFAULT NULL,`fd2` INT NULL DEFAULT NULL,`fd3` INT NULL DEFAULT NULL,`fd4` INT NULL DEFAULT NULL,`fd5` INT NULL DEFAULT '-1',`fd6` VARCHAR(16) binary NULL DEFAULT '-123456',`fd7` VARBINARY(50) NULL DEFAULT NULL,`fd8` TIMESTAMP(6) NULL DEFAULT NULL,`fd9` DATETIME(2) NULL DEFAULT NULL,`fd10` TIMESTAMP(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),`fd11` DATETIME(6) NULL DEFAULT NULL, UNIQUE key0(`id`), UNIQUE key1(`fd1`)) ENGINE=InnoDB default charset=utf8
*/
short createTestTable(database* db, bool timestampNull = true, bool supportDateTimeTimeStamp = true)
{
    try
    {
        openDatabase(db, makeUri(PROTOCOL, HOSTNAME, DBNAMEV3, BDFNAME), TYPE_SCHEMA_BDF,TD_OPEN_NORMAL);
        dbdef* def = db->dbDef();
        short tableid = 1;
        db->dropTable(_T("nulltest"));
        def->deleteTable(tableid);
        
        short fieldnum = 0;
        insertTable(def, tableid,  _T("nulltest"), g_td_charsetIndex);

        insertField(def, tableid, fieldnum, _T("id"), ft_integer, 4);
        fielddef* fd = insertField(def, tableid, ++fieldnum, _T("fd1"), ft_integer, 4);
        fd->setNullable(true);
        //fd->nullbit = 100;
        //fd->nullbytes = 30;

        fd = insertField(def, tableid, ++fieldnum, _T("fd2"), ft_integer, 4);
        fd->setNullable(true);
        fd = insertField(def, tableid, ++fieldnum, _T("fd3"), ft_integer, 4);
        fd->setNullable(true);
        fd = insertField(def, tableid, ++fieldnum, _T("fd4"), ft_integer, 4);
        fd->setNullable(true);
        fd = insertField(def, tableid, ++fieldnum, _T("fd5"), ft_integer, 4);
        fd->setNullable(timestampNull, false);
        fd->setDefaultValue(-1LL);
        fd = insertField(def, tableid, ++fieldnum, _T("fd6"), ft_myvarchar, 49);
        fd->setNullable(true, false);
        fd->setDefaultValue(_T("-123456"));
        //fd->setDefaultValue(_T("漢字"));
        fd = insertField(def, tableid, ++fieldnum, _T("fd7"), ft_myvarbinary, 51);
        fd->setNullable(true);
        fd = insertField(def, tableid, ++fieldnum, _T("fd8"), ft_mytimestamp, 7);
        fd->setNullable(timestampNull);
        fd->decimals = 6;

        fd = insertField(def, tableid, ++fieldnum, _T("fd9"), ft_mydatetime, 6);
        fd->setNullable(true);
        fd->decimals = 2;

        fd = insertField(def, tableid, ++fieldnum, _T("fd10"), ft_mytimestamp, 7);
        fd->setNullable(true);
        fd->decimals = 6;
        if (timestampNull == false && supportDateTimeTimeStamp)
        {
            fd->setDefaultValue(DFV_TIMESTAMP_DEFAULT);
            fd->setTimeStampOnUpdate(true);
        }

        fd = insertField(def, tableid, ++fieldnum, _T("fd11"), ft_mydatetime, 8);
        fd->setNullable(timestampNull);
        fd->decimals = 6;
        if (timestampNull == false && supportDateTimeTimeStamp)
            fd->setTimeStampOnUpdate(true);

        fd = insertField(def, tableid, ++fieldnum, _T("fd12"), ft_myyear, 1);
        fd->setNullable(true);

        keydef* kd = insertKey(def, tableid, 0);
        kd->segments[0].fieldNum = 0;
        kd->segments[0].flags.bit8 = 1; // extended key type
        kd->segments[0].flags.bit1 = 1; // changeable
        kd->segmentCount = 1;
        
        kd = insertKey(def, tableid, 1);
        kd->segments[0].fieldNum = 1;
        kd->segments[0].flags.bit8 = 1; // extended key type
        kd->segments[0].flags.bit1 = 1; // changeable
        kd->segmentCount = 1;
        tabledef* td = def->tableDefs(tableid);
        td->primaryKeyNum = 0;
        updateTableDef(def, tableid);
        return 0;
   
    }
    catch (bzs::rtl::exception& e)
    {
        _tprintf(_T("Error! %s\n"), (*getMsg(e)).c_str());
    }
    return 1;
}
예제 #18
0
파일: dag.c 프로젝트: shenchi/mycc
qcode_t undag(){
	qcode_t ret = 0, nc;
	dnode cur = nodes;
	nodelist p = dnodelist; 
	ident_t nid;

	while(p){
		if(!(p->flag) && (p->addr->type != DAG_LEAF) && p->id->type == VAR){
			p->flag = 1;
			p->addr->oprand = p->id;
		}
		p = p->next;
	}

	while(cur){
		if(cur->type == DAG_OP && cur->oprand == 0){
			nid = createIdent();
			nid->name = ccgenname(namenum++, '$');
			nid->type = TEMP;
			nid->subtype = cur->vartype;
			nid->loc = LOC_LOCAL;
			insertTable(stab, nid);
			cur->oprand = nid;
		}
		cur = cur->next;
	}
	
	p = dnodelist;
	while(p){
		if(p->id->type == VAR && !(p->flag) && p->addr->oprand != p->id){
			nc = createQCode();
			nc->code = MOV;
			nc->op1 = p->addr->oprand;
			nc->op2 = 0;
			nc->opr = p->id;
			nc->next = ret;
			ret = nc;
		}
		p = p->next;
	}

	cur = getNode();

	while(cur){
		nc = createQCode();
		nc->code = cur->op;
		nc->op1 = nc->op2 = nc->opr = 0;
		if( cur->x ){
			if(cur->type <= DAG_INST)
				nc->op1 = cur->x->oprand;
			cur->x->nref--;
		}

		if( cur->y ){
			if(cur->type <= DAG_INST)
				nc->op2 = cur->y->oprand;
			cur->y->nref--;
		}
		
		if(cur->oprand){
			nc->opr = cur->oprand;
		}

		nc->next = ret;
		ret = nc;

		cur->type = DAG_DEAD;
		if(cur->l){
			cur = cur->l;
			cur->nref--;
		}else
			cur = cur->x;
		
		if(!cur || cur->type == DAG_LEAF || cur->nref)cur = getNode(); 
	}

	return ret;
}
예제 #19
0
파일: dag.c 프로젝트: shenchi/mycc
void dag(qcode_t *first, qcode_t *last){
	qcode_t p = *first, ret = 0, q;
	nodelist nr;
	dnode node, x, y, z, cur_inst = 0, new_inst;
	ident_t nid;
	if(p->code == NOP){
		q = p;
		ret = q;
	}

	while(p  && p->code != RET && (p->code < JGT || p->code > JMP)){
		if(p->code == MOV){
			nr = findlist(p->op1);
			if(!nr){
				node = createLeaf(p->op1);
				updatelist(p->op1, node);
			}else{
				node = nr->addr;
			}
			updatelist(p->opr, node);

		} else if(p->code!= CMP && p->code!=FCMP && p->code >= ADD && p->code <=FNEG){
			nr = findlist(p->op1);
			if(!nr){
				node = createLeaf(p->op1);
				updatelist(p->op1, node);
			}else{
				node = nr->addr;
			}
			x = node;
			y = 0;
			if(p->op2){
				nr = findlist(p->op2);
				if(!nr){
					node = createLeaf(p->op2);
					updatelist(p->op2, node);
				}else{
					node = nr->addr;
				}
				y = node;
			}
			nr = dnodelist;
			while(nr){
				z = nr->addr;
				if(z->op == p->code && z->x == x && z->y == y)
					break;
				nr = nr->next;
			}

			if(!nr){
				z = createNode(DAG_OP, p->code, 0, x, y);
			}else{
				z = nr->addr;
			}
			updatelist(p->opr, z);

		} else {
			if(p->op1){
				nr = findlist(p->op1);
				if(!nr){
					x = createLeaf(p->op1);
					updatelist(p->op1, x);
				}else{
					x = nr->addr;
				}
			}else{
				x = 0;
			}

			if(p->op2){
				nr = findlist(p->op2);
				if(!nr){
					y = createLeaf(p->op2);
					updatelist(p->op2, y);
				}else{
					y = nr->addr;
				}
			}else{
				y = 0;
			}

			new_inst = createNode(DAG_INST, p->code, cur_inst, x, y);
			cur_inst = new_inst;

			if(p->opr){
				nid = createIdent();
				nid->name = ccgenname(namenum++, '$');
				nid->type = TEMP;
				nid->subtype = p->opr->subtype;
				nid->loc = LOC_LOCAL;
				insertTable(stab, nid);
				cur_inst->oprand = nid;
				cur_inst->vartype = nid->subtype;
				updatelist(p->opr, cur_inst);
			}else{
				cur_inst->vartype = TVOID;
			}
		}

		p = p->next;
	}

	if(ret)
		ret->next = undag();
	else
		ret = undag();

	*first = ret;

	q = ret;
	while(q->next){
		q = q->next;
	}
	if(p){
		if(p->code == RET && p->opr){
			nr = findlist(p->opr);
			p->opr = nr->addr->oprand;
		}
		*last = p;	
		q->next = p;
		p->next = 0;
	}else{
		*last = q;
	}

	deleteNodes();
	clearnodelist();

}
예제 #20
0
int main() {
    
    char filename[MAX_SIZE+1], temp[MAX_SIZE+1];
    FILE *ifp;
    int numwords, i;
    struct htable mytable;
    int ans;
    
    // Get the file name.
    printf("What is the name of the dictionary file?\n");
    scanf("%s", &filename);
    ifp = fopen(filename, "r");
    
    fscanf(ifp, "%d", &numwords);
    
    // Read in all of the words from a file into the table.
    // This is only done once.
    printf("get here\n");
    initTable(&mytable);
    printf("iniit table\n");
    
    for (i=0; i<numwords; i++) {
        fscanf(ifp, "%s", temp);
        insertTable(&mytable, temp);
    }
    
    
    // Allow the user to make changes to the hash table and search for words.
    do {
       
        printf("Do you want to 1)search word, 2) add word, 3) delete a word?\n");
        scanf("%d", &ans);
       
        // Search for a word.
        if (ans == 1) {
                   
            printf("What word are you looking for?\n");
            scanf("%s", temp);
            if (searchTable(&mytable, temp))
                printf("%s was found.\n", temp);
            else
                printf("%s was NOT found.\n", temp);     
        }    
        
        // Add a word.
        else if (ans == 2) {
            
            printf("What word do you want to add?\n");
            scanf("%s", temp);
            if (searchTable(&mytable, temp))
                printf("%s was ALREADY in the table\n", temp);
            else 
                insertTable(&mytable, temp);     
        }
        
        // Delete a word.
        else if (ans == 3) {
        
            printf("What word do you want to delete?\n");
            scanf("%s", temp);
            deleteTable(&mytable, temp);
                 
        }
        
    } while (ans < 4); // Not very user friendly, just quits for any number > 3.
    
    system("PAUSE");
    return 0;
}