SlideServe
Menu
Préférences
© SlideServe · v2026

Introduction to Map and Dictionary ADTs: Dynamic Array Implementation of Key-Value Pairs

manning avatar
8 diapositives · 211 Views · Oct 15, 2014

This document introduces the Map (or Dictionary) Abstract Data Type (ADT) and illustrates its implementation using a dynamic array. It highlights the importance of associating keys with values, showcasing practical examples, such as phonebooks and word counts in texts, to demonstrate key-value pair storage. The Map allows for operations like putting, getting, checking key existence, and removing key-value pairs efficiently. The internal structure utilizes associations of keys and values, implementing dynamic arrays for flexibility and scalability in data handling.

Introduction to Map and Dictionary ADTs: Dynamic Array Implementation of Key-Value Pairs - slide 1
01 / 8Introduction to Map and Dictionary ADTs: Dynamic Array Implementation of Key-Value Pairs
1 / 17

Télécharger la présentation

Introduction to Map and Dictionary ADTs: Dynamic Array Implementation of Key-Value Pairs
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. CS261 Data Structures Maps (or Dictionaries)

  2. Goals • Introduce the Map(or Dictionary) ADT • Introduce an implementation of the map with a Dynamic Array

  3. So Far…. • Emphasis on values themselves • e.g. store names in an AVL tree to quickly lookup club members • e.g. store numbers in an AVL tree for a tree sort • Often, however, we want to associate something else (ie. a value) with the lookup value (ie. a key) • e.g. phonebook, dictionary, student roster, etc.

  4. Map or Dictionary ADT • A Map stores not just values, but Key-Value pairs • void put (KT key , VT value) • VT get (KT key) • intcontainsKey(KT key) • void removeKey (KT key) • Struct Association { • KT key; • VT value; • }; All comparisons done on the key All returned values are VT Can implement with AVLTree, HashTable, DynArr, etc.

  5. Dynamic Array Map: put void putDynArrayDictionary (structdyArray *data, KEYTYPE key, VALUETYPE val, comparator compareKey) { struct association * ap; if (containsKeyDynArrayDictionary(vec, key, compareKey)) removeKeyDynArrayDictionary (vec, key, compareKey); ap = (struct association *) malloc(sizeof(struct association)); assert(ap != 0); ap->key = key; ap->value = val; addDynArray(vec, ap); }

  6. Dynamic Array Map: Contains intcontainsMap (DynArr *v, KT key, comparator compare){ int i = 0; for (i = 0; i < v->size; i++) { if ((*compare)(((struct association *)(v->data[i]))->key, key) == 0 ) /* found it */ return 1; } return 0; }

  7. Map or Dictionary • A Map stores not just values, but Key-Value pairs • Example Application: Concordance • Count the number of times each word appears in a selection of text • Keys: unique words form the text • Value: count of each word

  8. Your Turn – Worksheet 36: Dynamic Array Implementation of the Map • Internally, store Struct Associations • Put • Ensure that each element in the dictionary has a unique key • ContainsKey • Loop until you find the ‘key’ and then return true, else false • Get • Loop until you find the ‘key’ then return the value • RemoveKey • Loop until you find the ‘key’, then remove the entire association