/* *NOTE: I modified Dr.Brass code to return a long, his doesn't */ long integraton_test(){ long i,j; bf_t *bloom; bloom = create_bf(); printf("Created Filter\n"); for( i= 0; i< 100000; i++ ) { char s[8]; sample_string_A(s,i); insert_bf( bloom, s ); } for( i= 0; i< 50000; i++ ) { char s[7]; sample_string_B(s,i); insert_bf( bloom, s ); } for( i= 0; i< 50000; i++ ) { char s[6]; sample_string_C(s,i); insert_bf( bloom, s ); } printf("inserted 200000 strings of length 8,7,6.\n"); for( i= 0; i< 100000; i++ ) { char s[8]; sample_string_A(s,i); if( is_element( bloom, s ) != 1 ) { printf("found negative error (1)\n"); exit(0); } } for( i= 0; i< 50000; i++ ) { char s[7]; sample_string_B(s,i); if( is_element( bloom, s ) != 1 ) { printf("found negative error (2)\n"); exit(0); } } for( i= 0; i< 50000; i++ ) { char s[6]; sample_string_C(s,i); if( is_element( bloom, s ) != 1 ) { printf("found negative error (3)\n"); exit(0); } } j = 0; for( i= 0; i< 200000; i++ ) { char s[8]; sample_string_D(s,i); if( is_element( bloom, s ) != 0 ) j+=1; } for( i= 0; i< 200000; i++ ) { char s[8]; sample_string_E(s,i); if( is_element( bloom, s ) != 0 ) j+=1; } printf("Found %ld positive errors out of 400000 tests.n",j); return j; }
int Ioss::ElementTopology::number_boundaries() const { if (parametric_dimension() == 3 && spatial_dimension() == 3) return number_faces(); if (parametric_dimension() == 2 && spatial_dimension() == 2) return number_edges(); if (parametric_dimension() == 1 && !is_element()) return number_corner_nodes(); if (is_element()) { if (parametric_dimension() == 2) { assert(spatial_dimension() == 3); // A shell has faces and edges in its boundary... return number_faces() + number_edges(); } else if (parametric_dimension() == 1) { return number_edges(); } } else { if (parametric_dimension() == 2) { assert(spatial_dimension() == 3); return number_edges(); } } return 0; }
int main() { long i,j; bf_t * bloom; bloom = create_bf(); printf("Created Filter\n"); for( i= 0; i< 1450000; i++ ) { char s[8]; sample_string_A(s,i); insert_bf( bloom, s ); } for( i= 0; i< 500000; i++ ) { char s[7]; sample_string_B(s,i); insert_bf( bloom, s ); } for( i= 0; i< 50000; i++ ) { char s[6]; sample_string_C(s,i); insert_bf( bloom, s ); } printf("inserted 2,000,000 strings of length 8,7,6.\n"); for( i= 0; i< 1450000; i++ ) { char s[8]; sample_string_A(s,i); if( is_element( bloom, s ) != 1 ) { printf("found negative error (1)\n"); exit(0); } } for( i= 0; i< 500000; i++ ) { char s[7]; sample_string_B(s,i); if( is_element( bloom, s ) != 1 ) { printf("found negative error (2)\n"); exit(0); } } for( i= 0; i< 50000; i++ ) { char s[6]; sample_string_C(s,i); if( is_element( bloom, s ) != 1 ) { printf("found negative error (3)\n"); exit(0); } } j = 0; for( i= 0; i< 500000; i++ ) { char s[8]; sample_string_D(s,i); if( is_element( bloom, s ) != 0 ) j+=1; } for( i= 0; i< 500000; i++ ) { char s[7]; sample_string_E(s,i); if( is_element( bloom, s ) != 0 ) j+=1; } printf("Found %d positive errors out of 1,000,000 tests.\n",j); printf("Positive error rate %f\%.\n", (float)j/10000.0); }
void Validator::check_tag_levels() { if (!is_element(_root, XSL_STYLESHEET)) { _os << "root directives should be " << XSL_STYLESHEET << std::endl; _good = false; } for (auto it : _root.children()) { CompositeElement * ce = dynamic_cast<CompositeElement *>(it); if (ce != nullptr) { // Test presence of things different from a template on level 2 std::string xsl_operation = ce->ns_split().second; if (xsl_operation != XSL_TEMPLATES) { _os << "first child directives should all be " << XSL_TEMPLATES << std::endl; _good = false; } else { check_tag_lower_levels(*ce); } } else { // This would indicate that this differs from a composite // element therefore it can't be a template _os << "xsl level 2 tag incorrect" << std::endl; _good = false; } } }
Ioss::IntVector Ioss::ElementTopology::boundary_connectivity(int edge_number) const { if (parametric_dimension() == 3 && spatial_dimension() == 3) return face_connectivity(edge_number); if (parametric_dimension() == 2 && spatial_dimension() == 2) return edge_connectivity(edge_number); if (is_element()) { if (parametric_dimension() == 2) { assert(spatial_dimension() == 3); // A shell has faces and edges in its boundary... if (edge_number > number_faces()) { return edge_connectivity(edge_number - number_faces()); } else { return face_connectivity(edge_number); } } else if (parametric_dimension() == 1) { return edge_connectivity(edge_number); } } else { if (parametric_dimension() == 2) { assert(spatial_dimension() == 3); return edge_connectivity(edge_number); } } return Ioss::IntVector(); }
Document::Document(XMLDocument const & doc): _root_template(), _templates() { for (auto child : doc.root()->children()) { Element * element = dynamic_cast<Element *>(child); if (element != nullptr && is_element(*element, XSL_TEMPLATES)) { for (auto attr : element->attributes()) { if (attr->name() == XSL_MATCH && !attr->value().empty()) { if (attr->value() == "/") { _root_template = dynamic_cast<CompositeElement const *>(element); } else { _templates[attr->value()] = element; } break; // because f**k you that's why ! } } } } }
CL_CSSLayoutElement CL_CSSLayoutNode::to_element() const { if (is_element()) return CL_CSSLayoutElement(impl); else return CL_CSSLayoutElement(); }
Ioss::ElementTopology* Ioss::ElementTopology::boundary_type(int face_number) const { if (parametric_dimension() == 3 && spatial_dimension() == 3) return face_type(face_number); if (parametric_dimension() == 2 && spatial_dimension() == 2) return edge_type(face_number); if (is_element()) { if (parametric_dimension() == 2) { // A shell has faces and edges in its boundary... if (face_number == 0) return nullptr; assert(spatial_dimension() == 3); if (face_number > number_faces()) { return edge_type(face_number - number_faces()); } else { return face_type(face_number); } } else if (parametric_dimension() == 1) { return edge_type(face_number); } } else { if (parametric_dimension() == 2) { assert(spatial_dimension() == 3); return edge_type(face_number); } } return nullptr; }
mxml_node * node_identify( void * doc, const mxml_char_t * str, parsing_context *ctx ) { mxml_node * doc_node = (mxml_node *)doc; mxml_node * ident_node = NULL; UNUSED_ARG( ctx ); if ( !doc_node ) return NULL; if ( is_declaration ( str ) ) ident_node = create_declaration( doc_node ); else if ( is_comment( str ) ) ident_node = create_comment( doc_node ); else if ( is_unknown( str ) ) ident_node = create_unknown( doc_node ); else if ( is_element( str ) ) ident_node = create_element( XML_T(""), doc_node ); else if ( is_text( str ) ) ident_node = create_text( doc_node ); else ident_node = create_unknown( doc_node ); return ident_node; }
bool is_vertex(FBArray3D<unsigned char> &bvfmap,long i1,long i2,long i3) { for (int d1=-1; d1<=0; d1++) for (int d2=-1; d2<=0; d2++) for (int d3=-1; d3<=0; d3++) if (is_element(bvfmap,i1+d1,i2+d2,i3+d3)) return true; return false; }
bool Script::ResultIsElement() { if (this->result_.vt == VT_DISPATCH) { CComQIPtr<IHTMLElement> is_element(this->result_.pdispVal); if (is_element) { return true; } } return false; }
void ht_atom_set(ht_atom_t ht, atom key, void* val){ //find deleted or null element int pos = ht_atom_keypos(ht, key, ht_hashpos(ht, key), 1); if (is_element(ht->keys[pos]) && val == NULL){ ht->filled--; } if (!is_element(ht->keys[pos]) && val != NULL){ ht->filled++; } if (!val){ ht->keys[pos] = DELETED; }else{ ht->keys[pos] = key; ht->values[pos] = val; } //We may need to rehash at this point int newsize = ht->capacity; int fullness = (100 * ht->filled) / ht->capacity; if (fullness > 60) newsize = ht->capacity * 2; else if (fullness < 10) newsize = ht->capacity / 2; if (newsize < DEFAULT_SIZE) newsize = ht->capacity; if (newsize != ht->capacity){ //rehash! atom* oldkeys = ht->keys; void** oldvals = ht->values; int oldcap = ht->capacity; ht->keys = calloc(newsize, sizeof(atom)); ht->values = calloc(newsize, sizeof(void*)); ht->capacity = newsize; ht->filled = 0; for (int i=0;i<oldcap;i++){ if (is_element(oldkeys[i])) ht_atom_set(ht, oldkeys[i], oldvals[i]); } } }
void XMLSettingsMap::remove(const std::string &key) { for (auto cur = node->first_child(); cur; cur = cur->next_sibling()) { if (!cur->is_element()) continue; if (cur->attribute("key") == key) { node->remove_child(cur); break; } } }
void Parser::parse( const char *str, int len, bool end ) { const char *p = str; const char *pos = p; const char *s = 0;//数据开始位置 const char *e = 0;//数据结束位置 while( len > 0 ) { if( *p == '<' ) { pos = p; if( s ) e = p;//记下数据结束位置 } else if( *p=='>' ) { std::string tag( pos + 1, p - pos - 1 ); reArrange(tag); if( is_version( tag ) ) ;//std::cout << tag << "\n"; else if(is_help(tag)) ; else if( is_end( tag ) ) { if( s && e ) { std::string data( s + 1, e -s - 1 ); on_data( data ); s = e = 0; } on_end( tag ); } else if( is_element( tag ) ) { parse_property( tag ); on_end( tag ); } else { parse_property( tag ); s = p;//记下数据开位置 } } p++; len--; } }
XMLSettings XMLSettingsMap::get(const std::string &key) { for (auto cur = node->first_child(); cur; cur = cur->next_sibling()) { if (!cur->is_element()) continue; if (cur->attribute("key") == key) return XMLSettings(document, cur); } auto cur = node->owner_document()->create_element("item"); cur->set_attribute("key", key); node->append_child(cur); return XMLSettings(document, cur); }
bool CL_CSSBoxNodeWalker::next(bool traverse_children) { CL_CSSBoxNode *next = 0; if (traverse_children && is_element() && !get_element()->is_display_none()) next = cur->get_first_child(); if (next) level++; else next = cur->get_next_sibling(); while (cur && !next && level > 0) { level--; cur = cur->get_parent(); if (cur) next = cur->get_next_sibling(); } cur = next; return is_node(); }
void Validator::check_that_directive_has_attribute_r(Element const & root, std::string const & directive, std::string const & attr_name) { for (auto child : root.children()) { auto e = dynamic_cast<Element const *>(child); if (e != nullptr) { if (is_element(*e, directive)) { auto attr = e->find_attribute(attr_name); if (attr == nullptr || attr->value().empty()) { _os << "directive needs a " << attr_name << " attribute" << std::endl; _good = false; } } check_that_directive_has_attribute_r(*e, directive, attr_name); } } }
void TemplateRenderer::render_empty(Element const * tmplt) { if (is_element(*tmplt)) { render_xsl(tmplt); } else { auto ce = dynamic_cast<CompositeElement const *>(tmplt); if (ce == nullptr) { _os << tmplt->str() << std::endl; } else { _os << ce->begin_str() << std::endl; render_composite(ce); _os << ce->end_str() << std::endl; } } }
Node& Node::sanitize(const Whitelist& whitelist){ // Element nodes get checked if(is_element()){ // Is tag name allowed? bool ok = false; std::string tag = name(); for(auto item : whitelist){ if(tag==item.first){ ok = true; // Are attribute names allowed? for(auto attr : attrs()){ bool ok = false; for(auto allowed : item.second){ if(attr==allowed){ ok = true; break; } } // Attribute is not allowed...erase it if(not ok) erase(attr); } break; } } if(not ok) { // Tag name is not allowed... remove it from parent destroy(); } else { // Tag name is allowed...check children for(Node& child : children()) child.sanitize(whitelist); } } // Document and text nodes are not checked, only their children (if any) else { for(Node& child : children()) child.sanitize(whitelist); } return *this; }
static int dissect_banana_element(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int offset) { proto_item *ti; proto_tree *list_tree; guint8 byte = 0; gint64 val = 0; gint val_len = 0; int start_offset = offset; int old_offset; int i; /* Accumulate our value/length 'til we hit a valid type */ while (tvb_length_remaining(tvb, offset) > 0) { byte = tvb_get_guint8(tvb, offset); offset++; if (byte & 0x80) { if (is_element(byte)) { break; } else { expert_add_info_format(pinfo, NULL, &ei_banana_unknown_type, "Unknown type %u", byte); } } else { val_len++; if (val_len > MAX_ELEMENT_VAL_LEN) { expert_add_info(pinfo, NULL, &ei_banana_too_many_value_bytes); } val += byte + (val << 7); } } /* Type */ switch (byte) { case BE_LIST: if (val > MAX_ELEMENT_VAL) { expert_add_info_format(pinfo, NULL, &ei_banana_length_too_long, "List length %" G_GINT64_MODIFIER "d longer than we can handle", val); } ti = proto_tree_add_uint_format_value(tree, hf_banana_list, tvb, start_offset, offset - start_offset - 1, (guint32) val, "(%d items)", (gint) val); list_tree = proto_item_add_subtree(ti, ett_list); for (i = 0; i < val; i++) { old_offset = offset; offset += dissect_banana_element(tvb, pinfo, list_tree, offset); if (offset <= old_offset) { return offset - start_offset; } } break; case BE_INT: if (val > MAX_ELEMENT_VAL) { expert_add_info_format(pinfo, NULL, &ei_banana_value_too_large, "Integer value %" G_GINT64_MODIFIER "d too large", val); } proto_tree_add_uint(tree, hf_banana_int, tvb, start_offset, offset - start_offset, (guint32) val); break; case BE_STRING: if (val > MAX_ELEMENT_VAL) { expert_add_info_format(pinfo, NULL, &ei_banana_length_too_long, "String length %" G_GINT64_MODIFIER "d longer than we can handle", val); } proto_tree_add_item(tree, hf_banana_string, tvb, offset, (guint32) val, ENC_ASCII|ENC_NA); offset += (gint) val; break; case BE_NEG_INT: if (val > MAX_ELEMENT_VAL) { expert_add_info_format(pinfo, NULL, &ei_banana_value_too_large, "Integer value -%" G_GINT64_MODIFIER "d too large", val); } proto_tree_add_int(tree, hf_banana_neg_int, tvb, start_offset, offset - start_offset, (gint32) val * -1); break; case BE_FLOAT: proto_tree_add_item(tree, hf_banana_float, tvb, offset, 8, ENC_BIG_ENDIAN); offset += 8; break; case BE_LG_INT: proto_tree_add_item(tree, hf_banana_lg_int, tvb, start_offset, offset - start_offset, ENC_NA); break; case BE_LG_NEG_INT: proto_tree_add_item(tree, hf_banana_lg_neg_int, tvb, start_offset, offset - start_offset, ENC_NA); break; case BE_PB: if (val_len > 1) { expert_add_info(pinfo, NULL, &ei_banana_pb_error); } /* * The spec says the pb dictionary value comes after the tag. * In real-world captures it comes before. */ proto_tree_add_item(tree, hf_banana_pb, tvb, offset - 2, 1, ENC_BIG_ENDIAN); break; default: return 0; break; } return offset - start_offset; }
DomElement DomNode::to_element() const { if (is_element()) return DomElement(impl); return DomElement(); }
ht_atom_iter ht_atom_next(ht_atom_iter i){ do{ i.idx ++; } while (i.idx < i.ht->capacity && !is_element(i.ht->keys[i.idx])); return i; }
static int parse_xml_tree_to_cache(xmlNode *root, const char *cachepath, const char *cachefile) { xmlNode *node, *node2, *node3, *node4 = NULL; char *name, *units, *value, *grid, *cluster, *host; FILE *f; char filenamebuf[PATH_MAX]; int count; for (node = root->children; node; node = node->next) { if (!is_element(node, "GRID")) continue; /* skip non-element and non-cluster nodes */ grid = get_prop(node, "NAME"); debug("Found new grid: %s\n", grid); for (node2 = node->children; node2; node2 = node2->next) { if (!is_element(node2, "CLUSTER")) continue; /* skip non-element and non-cluster nodes */ cluster = get_prop(node2, "NAME"); debug("\tFound new cluster: %s\n", cluster); for (node3 = node2->children; node3; node3 = node3->next) { if (!is_element(node3, "HOST")) continue; /* skip non-element and non-host nodes */ host = get_prop(node3, "NAME"); if (config.short_name) { host = get_shortname(host); } debug("\t\tFound new host: %s\n", host); snprintf(filenamebuf, PATH_MAX, "%s/%s/%s/%s", cachepath, grid, cluster, host); if (config.short_name) { free(host); } if (create_abs_path(filenamebuf) < 0) return -1; count = 0; f = fopen(filenamebuf, "w"); if (f == NULL) return -1; value = get_prop(node3, "REPORTED"); fprintf(f, "#REPORTED, ,%s\n", value); for (node4 = node3->children; node4; node4 = node4->next) { if (!is_element(node4, "METRIC")) continue; /* skip non-element and non-metric nodes */ name = get_prop(node4, "NAME"); units = get_prop(node4, "UNITS"); value = get_prop(node4, "VAL"); debug("\t\t\tFound new metric: %s\n", name); fprintf(f, "%s,%s,%s\n", name, units, value); count++; } fclose(f); debug("\t\t\tWrote %d metrics to %s\n", count, filenamebuf); } } } return 0; }
ht_int_iter ht_int_next(ht_int_iter i){ do{ i.idx ++; } while (i.idx < i.ht->capacity && !is_element(i.ht->values[i.idx])); return i; }