Exemplo n.º 1
0
void MapDestroy(Map *map)
{
    if (map)
    {
        if (IsArrayMap(map))
        {
            ArrayMapDestroy(map->arraymap);
        }
        else
        {
            HashMapDestroy(map->hashmap);
        }
        free(map);
    }
}
Exemplo n.º 2
0
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);
}