inline bool get_intersect(const circle& a, const circle &b, bool e_trick, vector<node> &s) { if (e_trick && a == b) { add_interval(s, -PI, PI); return true; } if (contain(a, b)) return false; if (contain(b, a)) { add_interval(s, -PI, PI); return true; } point l = b.center - a.center; double d = dis(a.center, b.center); if (d > a.radius + b.radius - EPS) return false; double theta = acos((sqr(a.radius) + sqr(d) - sqr(b.radius)) / 2 / a.radius / d); double c1 = atan2(l.y, l.x) - theta, c2 = atan2(l.y, l.x) + theta; if (c1 < -PI) c1 += 2 * PI; if (c2 > PI) c2 -= 2 * PI; if (c1 > c2) { add_interval(s, c1, PI); add_interval(s, -PI, c2); } else add_interval(s, c1, c2); return true; }
static int adjust_memory(struct pcmcia_socket *s, unsigned int action, unsigned long start, unsigned long end) { struct socket_data *data = s->resource_data; unsigned long size = end - start + 1; int ret = 0; if (end < start) return -EINVAL; down(&rsrc_sem); switch (action) { case ADD_MANAGED_RESOURCE: ret = add_interval(&data->mem_db, start, size); break; case REMOVE_MANAGED_RESOURCE: ret = sub_interval(&data->mem_db, start, size); if (!ret) { struct pcmcia_socket *socket; down_read(&pcmcia_socket_list_rwsem); list_for_each_entry(socket, &pcmcia_socket_list, socket_list) release_cis_mem(socket); up_read(&pcmcia_socket_list_rwsem); } break; default: ret = -EINVAL; } up(&rsrc_sem); return ret; }
static int adjust_io(struct pcmcia_socket *s, unsigned int action, unsigned long start, unsigned long end) { struct socket_data *data = s->resource_data; unsigned long size = end - start + 1; int ret = 0; if (end < start) return -EINVAL; if (end > IO_SPACE_LIMIT) return -EINVAL; down(&rsrc_sem); switch (action) { case ADD_MANAGED_RESOURCE: if (add_interval(&data->io_db, start, size) != 0) { ret = -EBUSY; break; } #ifdef CONFIG_PCMCIA_PROBE if (probe_io) do_io_probe(s, start, size); #endif break; case REMOVE_MANAGED_RESOURCE: sub_interval(&data->io_db, start, size); break; default: ret = -EINVAL; break; } up(&rsrc_sem); return ret; }
inline vector<double> area(const vector<circle> &a) { // return the area covered by at least x circlex int n = a.size(); vector<double> ret(n + 1, 0); for (int i = 0; i < n; ++i) { vector<node> s; int part = 0; double last; for (int j = 0; j < n; ++j) get_intersect(a[i], a[j], i < j, s); add_interval(s, -PI, PI); sort(s.begin(), s.end(), cmp); for (int j = 0; j < (int)s.size(); ++j) { if (part) ret[part] += calc_area(a[i], last, s[j].key); part += s[j].value; last = s[j].key; } } return ret; }
/** * Constructor. * * @intervals - if empty, will add the contigs found in the header files */ BCFSyncedStreamReader::BCFSyncedStreamReader(std::vector<std::string>& vcf_files, std::vector<GenomeInterval>& intervals, bool sync_by_pos) :vcf_files(vcf_files), intervals(intervals), sync_by_pos(sync_by_pos) { nfiles = vcf_files.size(); vcfs.resize(nfiles, 0); hdrs.resize(nfiles, 0); idxs.resize(nfiles, 0); tbxs.resize(nfiles, 0); itrs.resize(nfiles, 0); ftypes.resize(nfiles, -1); current_interval = ""; current_pos1 = 0; buffer.resize(nfiles); s = {0, 0, 0}; exists_selected_intervals = (intervals.size()!=0); for (uint32_t i=0; i<intervals.size(); ++i) { intervals_map[intervals[i].to_string()] = i; } intervals_index = 0; //1. check file type validity //2. loads indices //3. adds sequences found in all indexed files, this allows us to iterate through all sequences. for (int32_t i = 0; i<nfiles; ++i) { ftypes[i] = hts_file_type(vcf_files[i].c_str()); vcfs[i] = bcf_open(vcf_files[i].c_str(), "r"); if (vcfs[i]==NULL) exit(1); hdrs[i] = bcf_alt_hdr_read(vcfs[i]); if (i==0) { if (!(ftypes[i] & (FT_VCF|FT_BCF|FT_STDIN))) { fprintf(stderr, "[E:%s:%d %s] %s not a VCF or BCF file\n", __FILE__, __LINE__, __FUNCTION__, vcf_files[i].c_str()); exit(1); } if (!load_index(i)) { fprintf(stderr, "[I:%s:%d %s] index cannot be loaded for %s\n", __FILE__, __LINE__, __FUNCTION__, vcf_files[i].c_str()); exit(1); } if (!exists_selected_intervals) { //add sequences from file i add_interval(i); } } else { if (!(ftypes[i] & (FT_VCF_GZ|FT_BCF_GZ))) { fprintf(stderr, "[E:%s:%d %s] %s not a VCF_GZ or BCF file\n", __FILE__, __LINE__, __FUNCTION__, vcf_files[i].c_str()); exit(1); } if (!load_index(i)) { fprintf(stderr, "[E:%s:%d %s] index cannot be loaded for %s\n", __FILE__, __LINE__, __FUNCTION__, vcf_files[i].c_str()); exit(1); } if (!exists_selected_intervals) { //add sequences from file i add_interval(i); } } } }