1<!DOCTYPE html>
2<!--
3Copyright (c) 2013 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="import" href="/tracing/base/base.html">
9
10<script>
11'use strict';
12
13/**
14 * @fileoverview Provides the Event Index class.
15 */
16tr.exportTo('tr.model', function() {
17  /**
18   * A Event Index maps an id to all the events that have that particular id
19   *
20   * @constructor
21   */
22  function ModelIndices(model) {
23    // For now the only indices we construct are for flowEvents
24    this.flowEventsById_ = {};
25    model.flowEvents.forEach(function(fe) {
26      if (fe.id !== undefined) {
27        if (!this.flowEventsById_.hasOwnProperty(fe.id)) {
28          this.flowEventsById_[fe.id] = new Array();
29        }
30        this.flowEventsById_[fe.id].push(fe);
31      }
32    }, this);
33  }
34
35  ModelIndices.prototype = {
36    addEventWithId: function(id, event) {
37      if (!this.flowEventsById_.hasOwnProperty(id)) {
38        this.flowEventsById_[id] = new Array();
39      }
40      this.flowEventsById_[id].push(event);
41    },
42
43    getFlowEventsWithId: function(id) {
44      if (!this.flowEventsById_.hasOwnProperty(id))
45        return [];
46      return this.flowEventsById_[id];
47    }
48  };
49
50  return {
51    ModelIndices: ModelIndices
52  };
53});
54</script>
55
56