lexer::id_type lexer::add_literal( char const* literal ) { static char const chars_to_escape[] = ".^$*+-?()[]{}|\\/"; std::string const key = literal; id_type const token_id = get_next_id(); std::string token_def; for( std::size_t start = 0; start < key.size(); ) { std::size_t const next = key.find_first_of( chars_to_escape, start ); std::size_t end; if( next != std::string::npos ) { token_def.push_back( '\\' ); end = next + 1; } else { end = key.size(); } token_def.insert( token_def.end() , key.begin() + start, key.begin() + end ); start = end; } self.add( token_def, token_id ); tokens[ key ] = token_id; return token_id; }
int GeUser::add_user(char* system, char* user, char* password, pwr_tMask priv, char* fullname, char* description, char* email, char* phone, char* sms, pwr_tOix id) { SystemList* sl; int sts; // Find system SystemName* sn = new SystemName(system); sts = sn->parse(); if (EVEN(sts)) { delete sn; return sts; } sl = find_system(sn); if (!sl) return USER__NOSUCHSYSTEM; if (id == user_cNId) id = get_next_id(); else if (id >= next_id) next_id = id + 1; sl->add_user( id, user, password, priv, fullname, description, email, phone, sms); return USER__SUCCESS; }
bool im_login_list::update(/*in, out*/ im_login_id& _login) { bool found = false; for (auto iter = logins_.begin(); iter != logins_.end(); ++iter) { if (iter->get_login() == _login.get_login()) { found = true; _login = *iter; if (iter == logins_.begin()) return true; logins_.erase(iter); break; } } if (!found) _login.set_id(get_next_id()); logins_.push_front(_login); save(); return found; }
TEST(KeyBtreeTest, search) { StringBtree btree(TEST_KEY_MAX_SIZE); { TestKey key; int32_t j; int32_t *ids = (int32_t*)malloc(TEST_COUNT * sizeof(int32_t)); for(int32_t i = 0; i < TEST_COUNT; i++) { if (get_next_id(j)) break; ids[i] = j; key.set_value(j); btree.put(key, j + 1); } // search int32_t value = 0; int32_t success = 0; for(int32_t i = 0; i < TEST_COUNT; i++) { key.set_value(ids[i]); btree.get(key, value); if (value == ids[i] + 1) success ++; } free(ids); EXPECT_EQ(success, TEST_COUNT); } btree.clear(); }
TEST(KeyBtreeTest, put) { StringBtree btree(TEST_KEY_MAX_SIZE); { TestKey key; int32_t ret, j; int32_t success = 0; int32_t value = 0; for(int32_t i = 0; i < TEST_COUNT; i++) { if (get_next_id(j)) break; key.set_value(j); ret = btree.put(key, i + 1); if (ret == ERROR_CODE_OK) { success ++; } } EXPECT_EQ(success, btree.get_object_count()); ret = btree.put(key, 1); EXPECT_EQ(ret, ERROR_CODE_KEY_REPEAT); ret = btree.put(key, 20, true); EXPECT_EQ(ret, ERROR_CODE_OK); EXPECT_EQ(btree.get(key, value), ERROR_CODE_OK); EXPECT_TRUE(value == 20); EXPECT_EQ(success, btree.get_object_count()); } btree.clear(); }
void Pgr_linear<G>::add_shortcut( G &graph, V vertex, E incoming_edge, E outgoing_edge) { pgassert(incoming_edge != outgoing_edge); auto a = graph.adjacent(vertex, incoming_edge); auto c = graph.adjacent(vertex, outgoing_edge); pgassert(a != vertex); pgassert(a != c); pgassert(vertex != c); if (graph.is_undirected()) { Identifiers<V> adjacent_vertices = graph.find_adjacent_vertices(vertex); V vertex_1 = adjacent_vertices.front(); adjacent_vertices.pop_front(); V vertex_2 = adjacent_vertices.front(); adjacent_vertices.pop_front(); E shortcut_E; CH_edge shortcut(get_next_id(), graph[vertex_1].id, graph[vertex_2].id, graph[incoming_edge].cost + graph[outgoing_edge].cost); shortcut.add_contracted_vertex(graph[vertex], vertex); shortcut.add_contracted_edge_vertices(graph[incoming_edge]); shortcut.add_contracted_edge_vertices(graph[outgoing_edge]); debug << "Adding shortcut\n"; debug << shortcut; graph.add_shortcut(shortcut); debug << "Added shortcut\n"; } else { CH_edge shortcut( get_next_id(), graph[a].id, graph[c].id, graph[incoming_edge].cost + graph[outgoing_edge].cost); shortcut.add_contracted_vertex(graph[vertex], vertex); shortcut.add_contracted_edge_vertices(graph[incoming_edge]); shortcut.add_contracted_edge_vertices(graph[outgoing_edge]); debug << "Adding shortcut\n"; debug << shortcut; graph.add_shortcut(shortcut); debug << "Added shortcut\n"; } }
static BOOL create_poi (const char* name, RoadMapPosition* coordinates, BOOL overide, void * cursor){ int id = get_next_id(); if (id < 0) return FALSE; g_request_cursors[id] = cursor; roadmap_log( ROADMAP_DEBUG, "create_poi - name = %s,lat-%d, lon=%d, id=%d",name, coordinates->latitude, coordinates->longitude, id ); return Realtime_TripServer_CreatePOI(name, coordinates, overide,id); }
TEST(KeyBtreeTest, insert_batch) { StringBtree btree(TEST_KEY_MAX_SIZE); { BtreeWriteHandle handle; TestKey key; int32_t ret, j; int32_t success = 0; int32_t value = 0; ret = btree.get_write_handle(handle); ASSERT_TRUE(ERROR_CODE_OK == ret); for(int32_t i = 0; i < TEST_COUNT; i++) { if (get_next_id(j)) break; key.set_value(j); ret = btree.put(handle, key, i + 1); if (ret == ERROR_CODE_OK) { success ++; } } handle.end(); EXPECT_EQ(success, btree.get_object_count()); { BtreeWriteHandle handle1; btree.get_write_handle(handle1); for(int32_t i = 0; i < TEST_COUNT; i++) { if (get_next_id(j)) break; key.set_value(j); btree.put(handle1, key, i + 1); } key.set_value(1000); btree.put(handle1, key, 1000); btree.get(handle1, key, value); EXPECT_EQ(1000, value); handle1.rollback(); } EXPECT_EQ(success, btree.get_object_count()); } btree.clear(); }
virtual const object& create( const std::function<void(object&)>& constructor ) override { auto id = get_next_id(); auto instance = id.instance(); if( instance >= _objects.size() ) _objects.resize( instance + 1 ); _objects[instance].id = id; constructor( _objects[instance] ); use_next_id(); return _objects[instance]; }
virtual const object& create(const std::function<void(object&)>& constructor )override { ObjectType item; item.id = get_next_id(); constructor( item ); auto insert_result = _indices.insert( std::move(item) ); FC_ASSERT(insert_result.second, "Could not create object! Most likely a uniqueness constraint is violated."); use_next_id(); return *insert_result.first; }
// use this to spawn new actors on the current process Actor* actor_train_protege (Actor *mentor, Role role, void *props){ Actor *actor = _train_actor(mentor, get_next_id(), role, props); if(mentor->proteges != NULL){ _add_new_protege(actor, mentor->proteges); } else{ mentor->proteges = _train_protege(actor); } return actor; }
/* buys a pass * * returns the id of the newly created Pass */ int Pass_Buy(Pass *pass, UserType const user, TermType const term, TransType const trans, int const amount, time_t const expires) { pass->balance = amount; pass->trans = trans; pass->term = term; pass->user = user; pass->id = get_next_id(); pass->expires = expires; return pass->id; }
// 登録 CALLBACK_ID set(F func, void *arg) { Item *item = get_free_item(); if (item == NULL) { return 0; } item->id = get_next_id(); item->entry = func; item->arg = arg; return item->id; }
virtual const object& create( const std::function<void(object&)>& constructor ) override { auto id = get_next_id(); auto instance = id.instance(); if( instance >= _objects.size() ) _objects.resize( instance + 1 ); _objects[instance].reset(new T); _objects[instance]->id = id; constructor( *_objects[instance] ); _objects[instance]->id = id; // just in case it changed use_next_id(); return *_objects[instance]; }
void loop_and_count (pthread_t self, Environment *env) { int id; while (1) { id = get_next_id (env); // printf ("%d got %d\n", self, id); if (id >= SIZE) return; env->array[id]++; } }
TEST(KeyBtreeTest, range_search) { StringBtree btree(TEST_KEY_MAX_SIZE); { BtreeReadHandle handle; TestKey key; int32_t j; int32_t *ids = (int32_t*)malloc(TEST_COUNT * sizeof(int32_t)); int insert_total = 0; for(int32_t i = 0; i < TEST_COUNT; i++) { if (get_next_id(j)) break; ids[i] = j; key.set_value(j); if (ERROR_CODE_OK == btree.put(key, i + 1)) { insert_total ++; } } // range search int32_t value = 0; int32_t success = 0; int32_t ret = btree.get_read_handle(handle); ASSERT_TRUE(ERROR_CODE_OK == ret); btree.set_key_range(handle, btree.get_min_key(), 0, btree.get_max_key(), 0); while(ERROR_CODE_OK == btree.get_next(handle, value)) { success ++; } EXPECT_EQ(success, insert_total); success = 0; BtreeReadHandle handle1; btree.get_read_handle(handle1); btree.set_key_range(handle1, btree.get_max_key(), 1, btree.get_min_key(), 1); if (ERROR_CODE_OK == btree.get_next(handle1, key, value)) { success ++; } while(ERROR_CODE_OK == btree.get_next(handle1, value)) { success ++; } EXPECT_EQ(success, insert_total); free(ids); } btree.clear(); }
int GeUser::add_system( char* name, pwr_tMask attributes, char* description, pwr_tOix id) { int sts; SystemName* sn = new SystemName(name); sts = sn->parse(); if (EVEN(sts)) { delete sn; return sts; } if (id == user_cNId) id = get_next_id(); else if (id >= next_id) next_id = id + 1; SystemList* sl = find_system(sn); if (sl) return USER__SYSTEMALREXIST; SystemName* parent = sn->parent(); if (!parent) { SystemList* sl; SystemList* system_list = new SystemList(id, name, 0, attributes, description); // Insert as last sibling to root if (!root) root = system_list; else { for (sl = root; sl->next; sl = sl->next) ; sl->next = system_list; } } else { parent->parse(); SystemList* sl = find_system(parent); if (!sl) { delete sn; delete parent; return USER__NOSUCHSYSTEM; } sl->add_system(id, sn, attributes, description); delete parent; } delete sn; return USER__SUCCESS; }
errval_t oct_sem_new(uint32_t* id, size_t value) { // Find a valid ID for our next semaphore *id = get_next_id(); //debug_printf("oct_sem_new id is: %d\n", *id); errval_t err = SYS_ERR_OK; for (size_t i=0; i < value; i++) { err = oct_sem_post(*id); if (err_is_fail(err)) { return err; } } return err; }
Matrix ParametricMesh::get_matrix(const std::string &sub_obj, const MtxParams &p) const { if(sub_obj == name) return param == -1 ? mtx : mtx * p[param]; const string subobj_id = get_next_id(sub_obj,name); for(const_sub_iterator i = sub_objs.begin(); i != sub_objs.end(); ++i) { if(subobj_id == i->name) { const Matrix &sub_mtx = i->get_matrix(sub_obj,p); return mtx * (param == -1 ? sub_mtx : p[param] * sub_mtx); } } throw_sub_obj_error(sub_obj,name); return Matrix(); }
unsigned apdb_add_begin(apdb_t* db, size_t length) { data_t data; assert(NULL != db && NONE == db->action && CAN_WRITE(db)); assert(db->index_file_len <= db->index_mmap_len); if (db->error) return -1; if (SSIZE_MAX - db->index_len <= db->index_file_len) { DEBUG("index file too big"); return -1; } if (SSIZE_MAX - ALIGN_UP(sizeof(data_t) + length, ALIGN_SIZE) <= db->data_file_len) { DEBUG("data file too big"); return -1; } db->next_id = get_next_id(db); if (db->error || UINT_MAX == db->next_id /* avoid overflow */) return -1; db->next_length = length; db->next_offset = db->data_file_len; db->next_written = 0; data.guard = GUARD; data.flags = 0; data.id = db->next_id; data.length = length; ERRORP_IF(sizeof(data_t) != writen(db->data_fd, &data, sizeof(data_t)), "failed to write"); db->data_file_len += sizeof(data_t); db->action = ADD; return data.id; L_error: db->error = -1; return -1; }
TEST(KeyBtreeTest, remove) { StringBtree btree(TEST_KEY_MAX_SIZE); { TestKey key; int32_t ret, j; int32_t *ids = (int32_t*)malloc(TEST_COUNT * sizeof(int32_t)); int32_t success = 0; int value; for(int32_t i = 0; i < TEST_COUNT; i++) { if (get_next_id(j)) break; ids[i] = j; key.set_value(j); if (btree.put(key, i + 1) == ERROR_CODE_OK) { success ++; } } key.set_value(0x80000000); ASSERT_TRUE(btree.put(key, 0x8000001) == ERROR_CODE_OK); btree.remove(key, value); ASSERT_TRUE(value == 0x8000001); // remove for(int32_t i = 0; i < TEST_COUNT - 10; i++) { key.set_value(ids[i]); ret = btree.remove(key); if (ret == ERROR_CODE_OK) { success --; } } free(ids); EXPECT_EQ(success, btree.get_object_count()); } btree.clear(); }
/****************************************************************************** * * * Function: * * * * Purpose: * * * * Parameters: * * * * Return value: * * * * Comments: * * * ******************************************************************************/ int register_db_table(JOBARG_EXEC_REQUEST er, zbx_uint64_t * inner_jobnet_id, int cnt) { const char *__function_name = "register_db_table"; char *user_name = NULL; char *jobnet_name = NULL; char *memo = NULL; char *jobnetid; char *env; char *value; int ret = SUCCEED; int res; int public_flag = 0; int run_type; int multiple_start_up; int i; zbx_uint64_t next_id; zbx_uint64_t update_date; zbx_uint64_t scheduled_time; DB_RESULT result; DB_ROW row; zabbix_log(LOG_LEVEL_DEBUG, "In %s() jobnetid: [%s]", __function_name, er.jobnetid); jobnetid = DBdyn_escape_string(er.jobnetid); result = DBselect ("select update_date, public_flag, multiple_start_up, user_name, jobnet_name, memo" " from ja_jobnet_control_table" " where jobnet_id='%s'" " and valid_flag=1", jobnetid); row = DBfetch(result); if (row == NULL) { ja_log("JATRAPPER200014", 0, jobnetid, 0, jobnetid); zbx_free(jobnetid); DBfree_result(result); ret = FAIL; return ret; } ZBX_STR2UINT64(update_date, row[0]); public_flag = atoi(row[1]); multiple_start_up = atoi(row[2]); user_name = DBdyn_escape_string(row[3]); jobnet_name = DBdyn_escape_string(row[4]); memo = DBdyn_escape_string(row[5]); DBfree_result(result); if (er.starttime != NULL) { run_type = JA_JOBNET_RUN_TYPE_SCHEDULED; ZBX_STR2UINT64(scheduled_time, er.starttime); } else { run_type = JA_JOBNET_RUN_TYPE_IMMEDIATE; scheduled_time = 0; } next_id = get_next_id(JA_RUN_ID_JOBNET_EX, 0, jobnetid, 0); if (next_id == 0) { ja_log("JATRAPPER200015", 0, jobnetid, 0); zbx_free(jobnetid); zbx_free(user_name); zbx_free(jobnet_name); zbx_free(memo); ret = FAIL; return ret; } res = DBexecute("insert into ja_run_jobnet_table" " (inner_jobnet_id, inner_jobnet_main_id," " update_date, run_type, main_flag, status, scheduled_time," " public_flag, multiple_start_up," " jobnet_id, user_name, jobnet_name, memo, execution_user_name)" " values ( " ZBX_FS_UI64 ", " ZBX_FS_UI64 ", " ZBX_FS_UI64 ", %d, %d, %d, " ZBX_FS_UI64 ", %d, %d," " '%s', '%s', '%s', '%s', '%s')", next_id, next_id, update_date, run_type, JA_JOBNET_MAIN_FLAG_MAIN, JA_JOBNET_STATUS_BEGIN, scheduled_time, public_flag, multiple_start_up, jobnetid, user_name, jobnet_name, memo, er.username); if (ZBX_DB_OK > res) { ja_log("JATRAPPER200016", 0, jobnetid, 0, jobnetid); zbx_free(jobnetid); zbx_free(user_name); zbx_free(jobnet_name); zbx_free(memo); ret = FAIL; return ret; } for (i = 0; i < cnt; i++) { env = NULL; value = NULL; env = DBdyn_escape_string(er.env[i]); value = DBdyn_escape_string(er.value[i]); res = DBexecute("insert into ja_value_before_jobnet_table" " (inner_jobnet_id, value_name, before_value)" " values ( " ZBX_FS_UI64 ", '%s', '%s' )", next_id, env, value); if (ZBX_DB_OK > res) { ja_log("JATRAPPER200016", 0, jobnetid, 0, jobnetid); zbx_free(jobnetid); zbx_free(user_name); zbx_free(jobnet_name); zbx_free(memo); zbx_free(env); zbx_free(value); ret = FAIL; return ret; } zbx_free(env); zbx_free(value); } *inner_jobnet_id = next_id; zbx_free(jobnetid); zbx_free(user_name); zbx_free(jobnet_name); zbx_free(memo); zabbix_log(LOG_LEVEL_DEBUG, "End of %s()", __function_name); return ret; }
/* * ui_handle_keycode - handle ui keycode * @key : key except to be HANG, BACK, 1~6 * @return : status */ int ui_handle_keycode(int key) { int cur_id, item_num; int next_id, parent_id; ACTION handler; cur_id = get_cur_frame_id(); if (key == BACK) { parent_id = get_parent_id(cur_id); if (cur_id == parent_id) return SUCCESS; pop_ui_statck(); set_cur_frame_id(parent_id); show_current_ui(parent_id); return SUCCESS; } if (key == HANG) { cmd_resume_transact(); set_cur_frame_id(cur_id); show_current_ui(cur_id); return SUCCESS; } item_num = get_item_num(cur_id); if (key > (item_num - 1)) return FAIL; next_id = get_next_id(cur_id, key); handler = get_next_action(cur_id, key); if (handler == NULL) { push_ui_statck(cur_id); set_cur_frame_id(next_id); show_current_ui(next_id); return SUCCESS; } else { handler(); push_ui_statck(cur_id); if (next_id == CLEAN_UI) { /* * just for log out and shutdown */ clear_screen(); } else { set_cur_frame_id(next_id); show_current_ui(next_id); } return SUCCESS; } }