UC3M

Telematic/Audiovisual Syst./Communication Syst. Engineering

Systems Architecture

September 2017 - January 2018

6.12.4.  Word Set Management

A C program needs to manipulate a set of words. We are asked to implement this functionality and the following description of the requirements is given:

  • The application must manipulate several set of words separately.

  • The order and form in which these words are stored in the data structure is irrelevant for the rest of the application.

  • The operations that must be supported are:

    1. Obtain an empty set.

    2. Given a word, obtain a set only with that word.

    3. Given a set and a word, obtain a new set containing the given word.

    4. Given a set and a word, return a set without the given word. If the word does not exist, the set is not modified.

    5. Destroy a given set of words.

  • All the operations receiving a word to be stored need to create a duplicate with the system call strdup. This function receives as parameter a zero-terminated string of type char * and returns a string (of type char *) which is a duplicate of the given parameter in a memory location that has been allocated with malloc.

  • The proposed solution must be compact, that is, have a memory usage as reduced as possible.

Work Plan

  1. In groups of four people, comment during five minutes the data structured proposed to manipulate these sets of words. Write its definition in C. Comment the proposed solution with the rest of the class. Derive a final proposal which will be the base for all the groups.

  2. The team proposes the implementation of the function to return an empty set and the function to return a set with a single word. Check the proposed solution with the teacher.

  3. The team proposes an implementation for the function that inserts a word in a set. Pay special attention to the data type that this function must return.

  4. Write the definitions of the headers of the two remaining functions (the one that removes an element from a set and the one that destroys a set).

  5. Let us suppose that we have written all the functions, now the rest of the application wants to use them, but as it was stated in the specification, the internal details of the data structure are irrelevant. How would you organize the code and the definitions to achieve this?

  6. Implement one of the two remaining functions.