ESR_ReturnCode SR_NametagsCreate(SR_Nametags** self) { SR_NametagsImpl* impl; ESR_ReturnCode rc; if (self == NULL) { PLogError(L("ESR_INVALID_ARGUMENT")); return ESR_INVALID_ARGUMENT; } impl = NEW(SR_NametagsImpl, MTAG); if (impl == NULL) { PLogError(L("ESR_OUT_OF_MEMORY")); return ESR_OUT_OF_MEMORY; } impl->Interface.load = &SR_NametagsLoadImpl; impl->Interface.save = &SR_NametagsSaveImpl; impl->Interface.add = &SR_NametagsAddImpl; impl->Interface.remove = &SR_NametagsRemoveImpl; impl->Interface.getSize = &SR_NametagsGetSizeImpl; impl->Interface.get = &SR_NametagsGetImpl; impl->Interface.getAtIndex = &SR_NametagsGetAtIndexImpl; impl->Interface.contains = &SR_NametagsContainsImpl; impl->Interface.destroy = &SR_NametagsDestroyImpl; impl->value = NULL; impl->eventLog = NULL; CHKLOG(rc, HashMapCreate(&impl->value)); CHKLOG(rc, ESR_SessionGetSize_t(L("SREC.Recognizer.osi_log_level"), &impl->logLevel)); if (impl->logLevel > 0) CHKLOG(rc, ESR_SessionGetProperty(L("eventlog"), (void **)&impl->eventLog, TYPES_SR_EVENTLOG)); CHKLOG(rc, SR_EventLogTokenPointer_BASIC(impl->eventLog, impl->logLevel, L("pointer"), self)); CHKLOG(rc, SR_EventLogEvent_BASIC(impl->eventLog, impl->logLevel, L("SR_NametagsCreate"))); *self = (SR_Nametags*) impl; return ESR_SUCCESS; CLEANUP: impl->Interface.destroy(&impl->Interface); return rc; }
void useCount(char* buffer, int N, int x1, int y1) { struct HashMap* A = HashMapCreate(MAXHASHVALUE, HashA); struct HashMap* B = HashMapCreate(MAXHASHVALUE, HashB); int i, x, y; char mode; Data NewData; NewData.a = x1; NewData.b = y1; HashMapAdd(A, NewData); HashMapAdd(B, NewData); int count = HashMapCount(A, NewData, cmpData); printf("%d\n", count); for(i = 1; i < N; i++) { scanf("%s ", buffer); if(strcmp(buffer, "ADD\0") == 0) { scanf("%d %d", &x, &y); Data NewData; NewData.a = x; NewData.b = y; HashMapAdd(A, NewData); HashMapAdd(B, NewData); int count = HashMapCount(A, NewData, cmpData); printf("%d\n", count); } else if(strcmp(buffer, "DELETE\0") == 0) { scanf("%c", &mode); if(mode == 'A') { scanf("%d", &x); Data NewData; NewData.a = x; int count = HashMapCount(A, NewData, cmpDataA); printf("%d\n", count); while(1) { Data* Del = HashMapDeleteOne(A, NewData, cmpDataA); if(Del != NULL) { HashMapDeleteOne(B, *Del, cmpData); } else break; } } if(mode == 'B') { scanf("%d", &y); Data NewData; NewData.b = y; int count = HashMapCount(B, NewData, cmpDataB); printf("%d\n", count); while(1) { Data* Del = HashMapDeleteOne(B, NewData, cmpDataB); if(Del != NULL) { HashMapDeleteOne(A, *Del, cmpData); } else break; } } } else if(strcmp(buffer, "COUNT\0") == 0) { scanf("%c", &mode); if(mode == 'A') { scanf("%d", &x); Data NewData; NewData.a = x; int count = HashMapCount(A, NewData, cmpDataA); printf("%d\n", count); } if(mode == 'B') { scanf("%d", &y); Data NewData; NewData.b = y; int count = HashMapCount(B, NewData, cmpDataB); printf("%d\n", count); } } else { printf("ERR\n"); } } HashMapDestroy(A); HashMapDestroy(B); }