char * sgml__utf8_get_char(const char *in, int *chr) { /* 2-byte, 0x80-0x7ff */ if ( (in[0]&0xe0) == 0xc0 && CONT(1) ) { *chr = ((in[0]&0x1f) << 6)|VAL(1,0); return (char *)in+2; } /* 3-byte, 0x800-0xffff */ if ( (in[0]&0xf0) == 0xe0 && CONT(1) && CONT(2) ) { *chr = ((in[0]&0xf) << 12)|VAL(1,6)|VAL(2,0); return (char *)in+3; } /* 4-byte, 0x10000-0x1FFFFF */ if ( (in[0]&0xf8) == 0xf0 && CONT(1) && CONT(2) && CONT(3) ) { *chr = ((in[0]&0x7) << 18)|VAL(1,12)|VAL(2,6)|VAL(3,0); return (char *)in+4; } /* 5-byte, 0x200000-0x3FFFFFF */ if ( (in[0]&0xfc) == 0xf8 && CONT(1) && CONT(2) && CONT(3) && CONT(4) ) { *chr = ((in[0]&0x3) << 24)|VAL(1,18)|VAL(2,12)|VAL(3,6)|VAL(4,0); return (char *)in+5; } /* 6-byte, 0x400000-0x7FFFFFF */ if ( (in[0]&0xfe) == 0xfc && CONT(1) && CONT(2) && CONT(3) && CONT(4) && CONT(5) ) { *chr = ((in[0]&0x1) << 30)|VAL(1,24)|VAL(2,18)|VAL(3,12)|VAL(4,6)|VAL(5,0); return (char *)in+4; } *chr = *in; return (char *)in+1; }
int igraph_i_merge(igraph_t *res, int mode, const igraph_t *left, const igraph_t *right, igraph_vector_t *edge_map1, igraph_vector_t *edge_map2) { long int no_of_nodes_left=igraph_vcount(left); long int no_of_nodes_right=igraph_vcount(right); long int no_of_nodes; long int no_edges_left=igraph_ecount(left); long int no_edges_right=igraph_ecount(right); igraph_bool_t directed=igraph_is_directed(left); igraph_vector_t edges; igraph_vector_t edges1, edges2; igraph_vector_long_t order1, order2; long int i, j, eptr=0; long int idx1, idx2, edge1=-1, edge2=-1, from1=-1, from2=-1, to1=-1, to2=-1; igraph_bool_t l; if (directed != igraph_is_directed(right)) { IGRAPH_ERROR("Cannot make union or intersection of directed " "and undirected graph", IGRAPH_EINVAL); } IGRAPH_VECTOR_INIT_FINALLY(&edges, 0); IGRAPH_VECTOR_INIT_FINALLY(&edges1, no_edges_left*2); IGRAPH_VECTOR_INIT_FINALLY(&edges2, no_edges_right*2); IGRAPH_CHECK(igraph_vector_long_init(&order1, no_edges_left)); IGRAPH_FINALLY(igraph_vector_long_destroy, &order1); IGRAPH_CHECK(igraph_vector_long_init(&order2, no_edges_right)); IGRAPH_FINALLY(igraph_vector_long_destroy, &order2); if (edge_map1) { switch (mode) { case IGRAPH_MODE_UNION: IGRAPH_CHECK(igraph_vector_resize(edge_map1, no_edges_left)); break; case IGRAPH_MODE_INTERSECTION: igraph_vector_clear(edge_map1); break; } } if (edge_map2) { switch (mode) { case IGRAPH_MODE_UNION: IGRAPH_CHECK(igraph_vector_resize(edge_map2, no_edges_right)); break; case IGRAPH_MODE_INTERSECTION: igraph_vector_clear(edge_map2); break; } } no_of_nodes=no_of_nodes_left > no_of_nodes_right ? no_of_nodes_left : no_of_nodes_right; /* We merge the two edge lists. We need to sort them first. For undirected graphs, we also need to make sure that for every edge, that larger (non-smaller) vertex id is in the second column. */ IGRAPH_CHECK(igraph_get_edgelist(left, &edges1, /*bycol=*/ 0)); IGRAPH_CHECK(igraph_get_edgelist(right, &edges2, /*bycol=*/ 0)); if (!directed) { for (i=0, j=0; i<no_edges_left; i++, j+=2) { if (VECTOR(edges1)[j] > VECTOR(edges1)[j+1]) { long int tmp=VECTOR(edges1)[j]; VECTOR(edges1)[j]=VECTOR(edges1)[j+1]; VECTOR(edges1)[j+1]=tmp; } } for (i=0, j=0; i<no_edges_right; i++, j+=2) { if (VECTOR(edges2)[j] > VECTOR(edges2)[j+1]) { long int tmp=VECTOR(edges2)[j]; VECTOR(edges2)[j]=VECTOR(edges2)[j+1]; VECTOR(edges2)[j+1]=tmp; } } } for (i=0; i<no_edges_left; i++) { VECTOR(order1)[i]=i; } for (i=0; i<no_edges_right; i++) { VECTOR(order2)[i]=i; } igraph_qsort_r(VECTOR(order1), no_edges_left, sizeof(VECTOR(order1)[0]), &edges1, igraph_i_order_edgelist_cmp); igraph_qsort_r(VECTOR(order2), no_edges_right, sizeof(VECTOR(order2)[0]), &edges2, igraph_i_order_edgelist_cmp); #define INC1() if ( (++idx1) < no_edges_left) { \ edge1 = VECTOR(order1)[idx1]; \ from1 = VECTOR(edges1)[2*edge1]; \ to1 = VECTOR(edges1)[2*edge1+1]; \ } #define INC2() if ( (++idx2) < no_edges_right) { \ edge2 = VECTOR(order2)[idx2]; \ from2 = VECTOR(edges2)[2*edge2]; \ to2 = VECTOR(edges2)[2*edge2+1]; \ } idx1 = idx2 = -1; INC1(); INC2(); #define CONT() switch (mode) { \ case IGRAPH_MODE_UNION: \ l = idx1 < no_edges_left || idx2 < no_edges_right; \ break; \ case IGRAPH_MODE_INTERSECTION: \ l = idx1 < no_edges_left && idx2 < no_edges_right; \ break; \ } CONT(); while (l) { if (idx2 >= no_edges_right || (idx1 < no_edges_left && from1 < from2) || (idx1 < no_edges_left && from1 == from2 && to1 < to2)) { /* Edge from first graph */ if (mode==IGRAPH_MODE_UNION) { IGRAPH_CHECK(igraph_vector_push_back(&edges, from1)); IGRAPH_CHECK(igraph_vector_push_back(&edges, to1)); if (edge_map1) { VECTOR(*edge_map1)[edge1]=eptr; } eptr++; } INC1(); } else if (idx1 >= no_edges_left || (idx2 < no_edges_right && from2 < from1) || (idx2 < no_edges_right && from1 == from2 && to2 < to1)) { /* Edge from second graph */ if (mode==IGRAPH_MODE_UNION) { IGRAPH_CHECK(igraph_vector_push_back(&edges, from2)); IGRAPH_CHECK(igraph_vector_push_back(&edges, to2)); if (edge_map2) { VECTOR(*edge_map2)[edge2]=eptr; } eptr++; } INC2(); } else { /* Edge from both */ IGRAPH_CHECK(igraph_vector_push_back(&edges, from1)); IGRAPH_CHECK(igraph_vector_push_back(&edges, to1)); if (mode==IGRAPH_MODE_UNION) { if (edge_map1) { VECTOR(*edge_map1)[edge1]=eptr; } if (edge_map2) { VECTOR(*edge_map2)[edge2]=eptr; } } else if (mode==IGRAPH_MODE_INTERSECTION) { if (edge_map1) { IGRAPH_CHECK(igraph_vector_push_back(edge_map1, edge1)); } if (edge_map2) { IGRAPH_CHECK(igraph_vector_push_back(edge_map2, edge2)); } } eptr++; INC1(); INC2(); } CONT(); } #undef INC1 #undef INC2 igraph_vector_long_destroy(&order2); igraph_vector_long_destroy(&order1); igraph_vector_destroy(&edges2); igraph_vector_destroy(&edges1); IGRAPH_FINALLY_CLEAN(4); IGRAPH_CHECK(igraph_create(res, &edges, no_of_nodes, directed)); igraph_vector_destroy(&edges); IGRAPH_FINALLY_CLEAN(1); return 0; }
void print_usage() { fprintf(stderr, "hugeadm [options]\n"); fprintf(stderr, "options:\n"); OPTION("--list-all-mounts", "List all current hugetlbfs mount points"); OPTION("--pool-list", "List all pools"); OPTION("--hard", "specified with --pool-pages-min to make"); CONT("multiple attempts at adjusting the pool size to the"); CONT("specified count on failure"); OPTION("--pool-pages-min <size|DEFAULT>:[+|-]<pagecount|memsize<G|M|K>>", ""); CONT("Adjust pool 'size' lower bound"); OPTION("--obey-mempolicy", "Obey the NUMA memory policy when"); CONT("adjusting the pool 'size' lower bound"); OPTION("--thp-always", "Enable transparent huge pages always"); OPTION("--thp-madvise", "Enable transparent huge pages with madvise"); OPTION("--thp-never", "Disable transparent huge pages"); OPTION("--thp-khugepaged-pages <pages to scan>", "Number of pages that khugepaged"); CONT("should scan on each pass"); OPTION("--thp-khugepaged-scan-sleep <milliseconds>", "Time in ms to sleep between"); CONT("khugepaged passes"); OPTION("--thp-khugepages-alloc-sleep <milliseconds>", "Time in ms for khugepaged"); CONT("to wait if there was a huge page allocation failure"); OPTION("--pool-pages-max <size|DEFAULT>:[+|-]<pagecount|memsize<G|M|K>>", ""); CONT("Adjust pool 'size' upper bound"); OPTION("--set-recommended-min_free_kbytes", ""); CONT("Sets min_free_kbytes to a recommended value to improve availability of"); CONT("huge pages at runtime"); OPTION("--set-recommended-shmmax", "Sets shmmax to a recommended value to"); CONT("maximise the size possible for shared memory pools"); OPTION("--set-shm-group <gid|groupname>", "Sets hugetlb_shm_group to the"); CONT("specified group, which has permission to use hugetlb shared memory pools"); OPTION("--add-temp-swap[=count]", "Specified with --pool-pages-min to create"); CONT("temporary swap space for the duration of the pool resize. Default swap"); CONT("size is 5 huge pages. Optional arg sets size to 'count' huge pages"); OPTION("--add-ramdisk-swap", "Specified with --pool-pages-min to create"); CONT("swap space on ramdisks. By default, swap is removed after the resize."); OPTION("--persist", "Specified with --add-temp-swap or --add-ramdisk-swap"); CONT("options to make swap space persist after the resize."); OPTION("--enable-zone-movable", "Use ZONE_MOVABLE for huge pages"); OPTION("--disable-zone-movable", "Do not use ZONE_MOVABLE for huge pages"); OPTION("--create-mounts", "Creates a mount point for each available"); CONT("huge page size on this system under /var/lib/hugetlbfs"); OPTION("--create-user-mounts <user>", ""); CONT("Creates a mount point for each available huge"); CONT("page size under /var/lib/hugetlbfs/<user>"); CONT("usable by user <user>"); OPTION("--create-group-mounts <group>", ""); CONT("Creates a mount point for each available huge"); CONT("page size under /var/lib/hugetlbfs/<group>"); CONT("usable by group <group>"); OPTION("--create-global-mounts", ""); CONT("Creates a mount point for each available huge"); CONT("page size under /var/lib/hugetlbfs/global"); CONT("usable by anyone"); OPTION("--max-size <size<G|M|K>>", "Limit the filesystem size of a new mount point"); OPTION("--max-inodes <number>", "Limit the number of inodes on a new mount point"); OPTION("--page-sizes", "Display page sizes that a configured pool"); OPTION("--page-sizes-all", "Display page sizes support by the hardware"); OPTION("--dry-run", "Print the equivalent shell commands for what"); CONT("the specified options would have done without"); CONT("taking any action"); OPTION("--explain", "Gives a overview of the status of the system"); CONT("with respect to huge page availability"); OPTION("--verbose <level>, -v", "Increases/sets tracing levels"); OPTION("--help, -h", "Prints this message"); }
static char * _fcitx_utf8_get_char(const char *i, uint32_t *chr) { const unsigned char* in = (const unsigned char *)i; if (!(in[0] & 0x80)) { *(chr) = *(in); return (char *)in + 1; } /* 2-byte, 0x80-0x7ff */ if ((in[0] & 0xe0) == 0xc0 && CONT(1)) { *chr = ((in[0] & 0x1f) << 6) | VAL(1, 0); return (char *)in + 2; } /* 3-byte, 0x800-0xffff */ if ((in[0] & 0xf0) == 0xe0 && CONT(1) && CONT(2)) { *chr = ((in[0] & 0xf) << 12) | VAL(1, 6) | VAL(2, 0); return (char *)in + 3; } /* 4-byte, 0x10000-0x1FFFFF */ if ((in[0] & 0xf8) == 0xf0 && CONT(1) && CONT(2) && CONT(3)) { *chr = ((in[0] & 0x7) << 18) | VAL(1, 12) | VAL(2, 6) | VAL(3, 0); return (char *)in + 4; } /* 5-byte, 0x200000-0x3FFFFFF */ if ((in[0] & 0xfc) == 0xf8 && CONT(1) && CONT(2) && CONT(3) && CONT(4)) { *chr = ((in[0] & 0x3) << 24) | VAL(1, 18) | VAL(2, 12) | VAL(3, 6) | VAL(4, 0); return (char *)in + 5; } /* 6-byte, 0x400000-0x7FFFFFF */ if ((in[0] & 0xfe) == 0xfc && CONT(1) && CONT(2) && CONT(3) && CONT(4) && CONT(5)) { *chr = ((in[0] & 0x1) << 30) | VAL(1, 24) | VAL(2, 18) | VAL(3, 12) | VAL(4, 6) | VAL(5, 0); return (char *)in + 6; } *chr = *in; return (char *)in + 1; }
hash_t hash_container(hash_iter_t iter) { return CONT(iter); }
hash_iter_t hash_next(hash_iter_t iter) { hash_iter_t nxt = list_next(iter); return enditer(nxt) ? firstiter(CONT(iter), HASH(iter) + 1) : nxt; }