MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / addState

Method addState

native/model/Graph.cpp:28–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26 const std::pair<int, double> Graph::_defaultDistri = std::make_pair(0, 0.0);
27
28 StatePtr Graph::addState(StatePtr state) {
29 auto activity = state->getActivityString(); // get the activity name(activity class name) of this new state
30 auto ifStateExists = this->_states.find(state); // try to find state in state caches
31 if (ifStateExists ==
32 this->_states.end()) // if this is a brand-new state, emplace this state inside _states cache
33 {
34 state->setId((int) this->_states.size());
35 this->_states.emplace(state);
36 } else {
37 if ((*ifStateExists)->hasNoDetail()) {
38 (*ifStateExists)->fillDetails(state);
39 }
40 state = *ifStateExists;
41 }
42
43 this->notifyNewStateEvents(state);
44
45 this->_visitedActivities.emplace(
46 activity); // add this activity name to this set, and in this set, every name is unique.
47 this->_totalDistri++;
48 std::string activityStr = *(activity.get());
49 if (this->_activityDistri.find(activityStr) ==
50 this->_activityDistri.end()) // try to find this activity name in the map of recording how many times one activity been accessed.
51 {
52 this->_activityDistri[activityStr] = _defaultDistri; // if not found, use the default pair of (0, 0) to initialize.
53 }
54 this->_activityDistri[activityStr].first++;
55 this->_activityDistri[activityStr].second =
56 1.0 * this->_activityDistri[activityStr].first / this->_totalDistri;
57 addActionFromState(state);
58 return state;
59 }
60
61
62 void Graph::notifyNewStateEvents(const StatePtr &node) {

Callers 1

getOperateOptMethod · 0.80

Calls 8

notifyNewStateEventsMethod · 0.95
getActivityStringMethod · 0.80
setIdMethod · 0.80
hasNoDetailMethod · 0.80
endMethod · 0.45
sizeMethod · 0.45
fillDetailsMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected