Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef PPAPI_SHARED_IMPL_VAR_GRAPH_H_ | |
| 6 #define PPAPI_SHARED_IMPL_VAR_GRAPH_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 #include <map> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "ppapi/c/pp_var.h" | |
| 14 | |
| 15 namespace ppapi { | |
| 16 | |
| 17 // PP_Vars form a graph when one PP_Var holds a reference to another PP_Var. | |
| 18 // For example PP_VARTYPE_ARRAY PP_Vars hold an array of other PP_Vars. | |
| 19 // A VarGraph is an intermediate representation of a graph of PP_Vars which is | |
|
dmichael (off chromium)
2013/04/12 22:40:38
nit: is is
raymes
2013/04/14 16:32:57
this is removed now
| |
| 20 // is useful for serializing the graph or converting it to some other format. | |
| 21 // The VarGraph is computed by computing the transitive closure of a | |
| 22 // starting node and storing them in |nodes|. | |
| 23 // | |
| 24 // |id_map| holds a mapping of the PP_Var |as_id| value to an index into | |
| 25 // |nodes|. For example if a PP_Var had an |as_id| value of 23 and was contained | |
| 26 // at index 2 in |nodes|, there would be an entry of 23->2 in |id_map|. Note | |
| 27 // that only PP_Vars that point to objects in the VarTracker are considered. | |
| 28 // Other PP_Vars are either primitives or null references which are guaranteed | |
| 29 // to be leaves in the graph. Since they cannot be identified by an id, they | |
| 30 // are not added to the list of nodes. | |
| 31 // | |
| 32 // Note: this is a very simple, minimal representation of a graph of | |
| 33 // PP_Vars. We could have a more complex structure later if it was warranted. | |
| 34 struct VarGraph { | |
|
dmichael (off chromium)
2013/04/12 22:40:38
This isn't really a Graph, best I can tell. It see
raymes
2013/04/14 16:32:57
This is removed now
| |
| 35 // Creates a VarGraph starting at |start_node| and storing the result in | |
| 36 // |result|. True is returned on success, false otherwise. | |
| 37 static bool Create(const PP_Var& start_node, VarGraph* result); | |
| 38 | |
| 39 std::vector<PP_Var> nodes; | |
| 40 std::map<int64_t, size_t> id_map; | |
|
dmichael (off chromium)
2013/04/12 22:40:38
hash map is probably a better choice for int64_t
raymes
2013/04/14 16:32:57
Done.
| |
| 41 }; | |
| 42 | |
| 43 } // namespace ppapi | |
| 44 | |
| 45 #endif // PPAPI_SHARED_IMPL_VAR_GRAPH_H_ | |
| OLD | NEW |