void test_set_remove (void) { Set* set; char buf[10]; int i; unsigned int num_entries; set = generate_set(); num_entries = set_num_entries (set); assert (num_entries == 10000); /* Remove some entries */ for (i = 4000; i < 6000; ++i) { sprintf (buf, "%i", i); /* Check this is in the set */ assert (set_query (set, buf) != 0); /* Remove it */ assert (set_remove (set, buf) != 0); /* Check the number of entries decreases */ assert (set_num_entries (set) == num_entries - 1); /* Check it is no longer in the set */ assert (set_query (set, buf) == 0); --num_entries; } /* Try to remove some invalid entries */ for (i = -1000; i < -500; ++i) { sprintf (buf, "%i", i); assert (set_remove (set, buf) == 0); assert (set_num_entries (set) == num_entries); } for (i = 50000; i < 51000; ++i) { sprintf (buf, "%i", i); assert (set_remove (set, buf) == 0); assert (set_num_entries (set) == num_entries); } set_free (set); }
void set_query(int o,int L,int R){ if(setv[o]>=0){ _sum+=setv[o]*(min(R,y2)-max(L,y1)+1); _min=min(_min,setv[o]); _max=max(_max,setv[o]); }else if(y1<=L && y2>=R){ _sum+=sumv[o]; _min= min(_min,minv[o]); _max= max(_max,maxv[o]); }else{ int M=L+(R-L)/2; if(y1<=M) set_query(o*2,L,M); if(y2> M) set_query(o*2,M+1,R); } }
void set_only_online(bool only_online) { if (only_online != only_online_) { only_online_ = only_online; User::set_s(SWITCH_ONLY_ONLINE_USERS, only_online); set_query(); } }
void set_not_removed(bool not_removed) { if (not_removed != not_removed_) { not_removed_ = not_removed; User::set_s(SWITCH_ONLY_NOT_REMOVED_USERS, not_removed); set_query(); } }
Set *set_union(Set *set1, Set *set2) { SetIterator iterator; Set *new_set; SetValue value; new_set = set_new(set1->hash_func, set1->equal_func); if (new_set == NULL) { return NULL; } /* Add all values from the first set */ set_iterate(set1, &iterator); while (set_iter_has_more(&iterator)) { /* Read the next value */ value = set_iter_next(&iterator); /* Copy the value into the new set */ if (!set_insert(new_set, value)) { /* Failed to insert */ set_free(new_set); return NULL; } } /* Add all values from the second set */ set_iterate(set2, &iterator); while (set_iter_has_more(&iterator)) { /* Read the next value */ value = set_iter_next(&iterator); /* Has this value been put into the new set already? * If so, do not insert this again */ if (set_query(new_set, value) == 0) { if (!set_insert(new_set, value)) { /* Failed to insert */ set_free(new_set); return NULL; } } } return new_set; }
void initialize() { last_used_ = 4 * WEEK; set_query(); addColumn("type", tr("tc.user.user")); // dummy addColumn("type", tr("tc.common.type")); // dummy addColumn("value", tr("tc.common.value")); addColumn("used", tr("tc.common.last")); addColumn("type", tr("tc.user.New_ban")); // dummy sort(LAST_USE, Wt::DescendingOrder); }
static int set_path(PyObject *env, char *buf, int len) { int c, c1, slen; char *s0, *t; PyObject *obj; t = s0 = buf; while(len > 0){ c = *buf++; if(c == '%' && len > 2){ c = *buf++; c1 = c; c = *buf++; c = hex2int(c1) * 16 + hex2int(c); len -= 2; }else if(c == '?'){ //stop if(set_query(env, buf, len) == -1){ //Error return -1; } break; }else if(c == '#'){ //stop //ignore fragment break; } *t++ = c; len--; } //*t = 0; slen = t - s0; slen = urldecode(s0, slen); obj = PyBytes_FromStringAndSize(s0, slen); /* DEBUG("path:%.*s", (int)slen, PyBytes_AS_STRING(obj)); */ if(likely(obj != NULL)){ #ifdef PY3 //TODO CHECK ERROR char *c2 = PyBytes_AS_STRING(obj); PyObject *v = PyUnicode_DecodeUTF8(c2, strlen(c2), NULL); PyDict_SetItem(env, path_info_key, v); Py_DECREF(v); #else PyDict_SetItem(env, path_info_key, obj); #endif Py_DECREF(obj); return slen; }else{ return -1; } }
void test_set_query (void) { Set* set; char buf[10]; int i; set = generate_set(); /* Test all values */ for (i = 0; i < 10000; ++i) { sprintf (buf, "%i", i); assert (set_query (set, buf) != 0); } /* Test invalid values returning zero */ assert (set_query (set, "-1") == 0); assert (set_query (set, "100001") == 0); set_free (set); }
void rss_feed::set_rssurl(const std::string& u) { rssurl_ = u; if (rssurl_.substr(0,6) == "query:") { std::vector<std::string> tokens = utils::tokenize_quoted(u, ":"); if (tokens.size() < 3) { throw std::string(_("too few arguments")); } LOG(LOG_DEBUG, "rss_feed::set_rssurl: query name = `%s' expr = `%s'", tokens[1].c_str(), tokens[2].c_str()); set_title(tokens[1]); set_query(tokens[2]); } }
void test_set_intersection (void) { int numbers1[] = {1, 2, 3, 4, 5, 6, 7}; int numbers2[] = {5, 6, 7, 8, 9, 10, 11}; int result[] = {5, 6, 7}; int i; Set* set1; Set* set2; Set* result_set; size_t allocated; /* Create the first set */ set1 = set_new (int_hash, int_equal); for (i = 0; i < 7; ++i) { set_insert (set1, &numbers1[i]); } /* Create the second set */ set2 = set_new (int_hash, int_equal); for (i = 0; i < 7; ++i) { set_insert (set2, &numbers2[i]); } /* Perform the intersection */ result_set = set_intersection (set1, set2); assert (set_num_entries (result_set) == 3); for (i = 0; i < 3; ++i) { assert (set_query (result_set, &result[i]) != 0); } /* Test out of memory scenario */ alloc_test_set_limit (0); assert (set_intersection (set1, set2) == NULL); /* Can allocate set, can't copy all values */ alloc_test_set_limit (2 + 2); allocated = alloc_test_get_allocated(); assert (set_intersection (set1, set2) == NULL); assert (alloc_test_get_allocated() == allocated); set_free (set1); set_free (set2); set_free (result_set); }
static int set_path(PyObject *env, char *buf, int len) { int c, c1, slen; char *s0, *t; PyObject *obj; t = s0 = buf; while(len > 0){ c = *buf++; if(c == '%' && len > 2){ c = *buf++; c1 = c; c = *buf++; c = hex2int(c1) * 16 + hex2int(c); len -= 2; }else if(c == '?'){ //stop if(set_query(env, buf, len) == -1){ //Error return -1; } break; }else if(c == '#'){ //stop //ignore fragment break; } *t++ = c; len--; } //*t = 0; slen = t - s0; slen = urldecode(s0, slen); #ifdef PY3 obj = PyUnicode_DecodeLatin1(s0, slen, "strict"); #else obj = PyBytes_FromStringAndSize(s0, slen); #endif if (likely(obj != NULL)) { PyDict_SetItem(env, path_info_key, obj); Py_DECREF(obj); return slen; } else { return -1; } }
UserListModel(Wt::WObject* parent = 0) : ULP::BaseQM(parent), only_blocked_(false) { only_online_ = User::has_s(SWITCH_ONLY_ONLINE_USERS); not_removed_ = User::has_s(SWITCH_ONLY_NOT_REMOVED_USERS); set_query(); addColumn("id", tr("tc.common.number")); // dummy addColumn("username", tr("tc.common.Name")); // dummy addColumn("classification", tr("tc.user.classification")); // dummy addColumn("games_stat_all", tr("tc.user.games_stat_all")); addColumn("games_stat_wins", tr("tc.user.games_stat_wins")); addColumn("id", tr("tc.user.games_stat_draws")); // dummy addColumn("games_stat_fails", tr("tc.user.games_stat_fails")); addColumn("games_stat_elo", tr("tc.user.games_stat_elo")); addColumn("online_time", tr("tc.user.Online_time").arg("")); // dummy addColumn("registration_date", tr("tc.user.Registration_date").arg("")); }
result_t Url::format(v8::Local<v8::Object> args) { clear(); Isolate* isolate = holder(); exlib::string str; v8::Local<v8::Value> v; if (getString(isolate, args, "protocol", str)) set_protocol(str); if (getString(isolate, args, "username", str)) set_username(str); if (getString(isolate, args, "password", str)) set_password(str); if (getString(isolate, args, "host", str)) set_host(str); if (getString(isolate, args, "port", str)) set_port(str); if (getString(isolate, args, "hostname", str)) set_hostname(str); if (getString(isolate, args, "pathname", str)) set_pathname(str); v = args->Get(holder()->NewString("query")); if (!IsEmpty(v)) set_query(v); if (getString(isolate, args, "hash", str)) set_hash(str); if (m_slashes && m_protocol.compare("file:") && m_hostname.length() == 0) m_slashes = false; v = args->Get(holder()->NewString("slashes")); if (!IsEmpty(v)) set_slashes(v->BooleanValue()); return 0; }
Set *set_intersection(Set *set1, Set *set2) { Set *new_set; SetIterator iterator; SetValue value; new_set = set_new(set1->hash_func, set2->equal_func); if (new_set == NULL) { return NULL; } /* Iterate over all values in set 1. */ set_iterate(set1, &iterator); while (set_iter_has_more(&iterator)) { /* Get the next value */ value = set_iter_next(&iterator); /* Is this value in set 2 as well? If so, it should be * in the new set. */ if (set_query(set2, value) != 0) { /* Copy the value first before inserting, * if necessary */ if (!set_insert(new_set, value)) { set_free(new_set); return NULL; } } } return new_set; }
query::query_iterator::query_iterator(query* cmd): cmd_(cmd) { set_query(cmd); }
void set_only_blocked(bool only_blocked) { if (only_blocked != only_blocked_) { only_blocked_ = only_blocked; set_query(); } }
builder &query(const string_type &query) { return set_query(query); }
void set_name_like(const Wt::WString& name_like) { if (name_like != name_like_) { name_like_ = name_like; set_query(); } }
builder &query(const string_type &key, const string_type &value) { return set_query(key, value); }
void set_last_used(const Td& last_used) { if (last_used != last_used_) { last_used_ = last_used; set_query(); } }