1 / 6

Locators

a. 3. Locators. g. e. 1. 4. Outline and Reading. Locators ( §2.4.4 ) Locator-based methods ( §2.4.4 ) Implementation Positions vs. Locators. A locators identifies and tracks a (key, element) item within a data structure

ruiza
Télécharger la présentation

Locators

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. a 3 Locators g e 1 4 Locators

  2. Outline and Reading • Locators (§2.4.4) • Locator-based methods (§2.4.4) • Implementation • Positions vs. Locators Locators

  3. A locators identifies and tracks a (key, element) item within a data structure A locator sticks with a specific item, even if that element changes its position in the data structure Intuitive notion: claim check reservation number Methods of the locator ADT: key(): returns the key of the item associated with the locator element(): returns the element of the item associated with the locator Application example: Orders to purchase and sell a given stock are stored in two priority queues (sell orders and buy orders) the key of an order is the price the element is the number of shares When an order is placed, a locator to it is returned Given a locator, an order can be canceled or modified Locators Locators

  4. Locator-based priority queue methods: insert(k, o): inserts the item (k, o) and returns a locator for it min(): returns the locator of an item with smallest key remove(l): remove the item with locator l replaceKey(l, k): replaces the key of the item with locator l replaceElement(l, o): replaces with o the element of the item with locator l locators(): returns an iterator over the locators of the items in the priority queue Locator-based dictionary methods: insert(k, o): inserts the item (k, o) and returns its locator find(k): if the dictionary contains an item with key k, returns its locator, else return the special locator NO_SUCH_KEY remove(l): removes the item with locator l and returns its element locators(), replaceKey(l, k), replaceElement(l, o) Locator-based Methods Locators

  5. Implementation d 6 • The locator is an object storing • key • element • position (or rank) of the item in the underlying structure • In turn, the position (or array cell) stores the locator • Example: • binary search tree with locators a b 3 9 g e c 1 4 8 Locators

  6. Position represents a “place” in a data structure related to other positions in the data structure (e.g., previous/next or parent/child) implemented as a node or an array cell Position-based ADTs (e.g., sequence and tree) are fundamental data storage schemes Locator identifies and tracks a (key, element) item unrelated to other locators in the data structure implemented as an object storing the item and its position in the underlying structure Key-based ADTs (e.g., priority queue and dictionary) can be augmented with locator-based methods Positions vs. Locators Locators

More Related