Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n,id;
- int hashIt(string ss)
- {
- int ret = 0;
- for(int i = 0; i < ss.size(); i++){
- ret = (ret+i*i)%n;
- }
- return ret;
- }
- class symbolInfo{
- private:
- string Name,Type;
- symbolInfo *nxt;
- public:
- symbolInfo() {}
- symbolInfo(string str1,string str2){
- Name = str1;
- Type = str2;
- }
- void setNxt(symbolInfo *p){
- nxt = p;
- }
- symbolInfo *getNxt(){
- return nxt;
- }
- string getName(){
- return Name;
- }
- string getType(){
- return Type;
- }
- };
- class scopeTable{
- public:
- int cnt;
- scopeTable *scopetable;
- symbolInfo *head;
- //scopeTable *nxt;
- //scopeTable *parentScope;
- scopeTable(){
- for(int i = 0; i < n; i++) {scopetable[i].head = NULL;cout << "no" << endl;}
- }
- ~scopeTable(){
- for(int i = 0; i < n; i++){
- symbolInfo *cur;
- cur = scopetable[i].head;
- while(cur != NULL){
- symbolInfo *tmp = cur;
- cur = cur->getNxt();
- delete tmp;
- }
- }
- delete scopetable;
- }
- bool Insert(int hashInd,string name,string type){
- cout << "yes yes" << endl;
- symbolInfo *newInfo = new symbolInfo(name,type);
- if(scopetable[hashInd].head == NULL){
- cout << "yes" << endl;
- scopetable[hashInd].head = newInfo;
- scopetable[hashInd].head->setNxt(NULL);
- scopetable[hashInd].cnt = 1;
- }
- else{
- cout << "no" << endl;
- newInfo->setNxt(scopetable[hashInd].head);
- scopetable[hashInd].head = newInfo;
- scopetable[hashInd].cnt++;
- }
- return 1;
- }
- /*bool Remove(string name){
- int Ind = hashIt[name];
- int hashInd = Ind % n;
- if(scopetable[hashInd].head == NULL){
- return 0;
- }
- symbolInfo *cur = scopetable[hashInd].head;
- symbolInfo *pre = scopetable[hashInd].head;
- while(cur != NULL){
- if(cur->getName() == name){
- if(cur == scopetable[hashInd].head){
- scopetable[hashInd].head = cur->getNxt();
- }
- else{
- pre->setNxt(cur->getNxt());
- }
- scopetable[hashInd].cnt--;
- delete cur;
- return 1;
- }
- pre = cur;
- cur = cur->getNxt();
- }
- return 0;
- }
- symbolInfo *LookUp(string name){
- int Ind = hashIt[name];
- int hashInd = Ind % n;
- if(scopetable[hashInd].head == NULL){
- return NULL;
- }
- symbolInfo *cur = scopetable[hashInd].head;
- while(cur != NULL){
- if(cur->getName() == name){
- return cur;
- }
- cur = cur->getNxt();
- }
- return NULL;
- }*/
- void Print(){
- symbolInfo *cur;
- for(int i = 0; i < n; i++){
- cout << i << "-->";
- if(scopetable[i].head == NULL){
- //cout << "naaaa " << endl;
- cout << endl;
- continue;
- }
- //cout << " bah ";
- cur = scopetable[i].head;
- while(cur != NULL){
- cout << " < " << cur->getName() << " " << cur->getType() << " > ";
- cur = cur->getNxt();
- }
- cout << endl;
- }
- }
- };
- /*class symbolTable{
- public:
- scopeTable *cur;
- symbolTable() {
- cout << "ok1" << endl;
- cur->parentScope = NULL;
- }
- void EnterScope(){
- scopeTable *newScope = new scopeTable;
- cout << "ok2" << endl;
- if(cur->parentScope == NULL){
- cout << "ok2" << endl;
- cur->parentScope = newScope;
- (cur->parentScope)->nxt = NULL;
- }
- else{
- newScope->nxt = cur->parentScope;
- cur->parentScope = newScope;
- }
- }
- scopeTable *ExitTable(scopeTable *now){
- scopeTable *tmp = now;
- now = now -> pre;
- cur = now;
- delete tmp;
- now->nxt = NULL;
- if(cur == NULL) return NULL;
- else return cur;
- }
- bool InsertIt(string s1,string s2){
- int key = hashFunc(s1);
- bool is = (curr->matha)->Insert(key,s1,s2);
- if(!is) return 0;
- else return 1;
- }
- void CurrentScopeTable(){
- (curr->matha)->Print();
- }
- };*/
- int main()
- {
- cin >> n;
- scopeTable *sc = new scopeTable();
- int cases,tt = 0;
- cin >> cases;
- while(++tt <= cases){
- int ya;
- cin >> ya;
- if(ya == 1){
- string aa,bb;
- cin >> aa >> bb;
- int val = hashIt(aa);
- sc->Insert(val,aa,bb);
- }
- else{
- sc->Print();
- }
- }
- delete sc;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement