1 // $Id: rangex.h,v 1.18 2011/12/29 23:44:19 ewalkup Exp $
2 
3 /*
4   Copyright 2002  Peter Beerli, Mary Kuhner, Jon Yamato and Joseph Felsenstein
5 
6   This software is distributed free of charge for non-commercial use
7   and is copyrighted.  Of course, we do not guarantee that the software
8   works, and are not responsible for any damage you may cause or have.
9 */
10 
11 #ifndef RANGEX_H
12 #define RANGEX_H
13 
14 #include <set>
15 #include <string>
16 #include <vector>
17 
18 struct rangecmp
19 {
operatorrangecmp20     bool operator()(const std::pair<long, long>& p1, const std::pair<long, long>& p2)
21     {
22         if (p1.first == p2.first)
23         {
24             return (p1.second < p2.second);
25         }
26         return (p1.first < p2.first);
27     }
28 };
29 
30 typedef std::pair<long,long>                    rangepair;
31 typedef std::vector<rangepair>                  rangevector;
32 typedef std::set<rangepair, rangecmp>           rangeset;
33 typedef std::set<rangepair, rangecmp>::iterator rangesetiter;
34 
35 std::string ToString(rangepair rpair);
36 std::string ToString(rangeset rset);
37 
38 rangeset MakeRangeset(long int low, long int high);
39 rangeset AddPairToRange(const rangepair& addpart, const rangeset& rset);
40 rangeset RemovePairFromRange(const rangepair& removepart, const rangeset& rset);
41 rangeset RemoveRangeFromRange(const rangeset& removerange, const rangeset& rset);
42 rangeset Union(const rangeset& set1, const rangeset& set2);
43 void     ORAppend(rangepair newrange, rangeset& oldranges);
44 rangeset Intersection(const rangeset& set1, const rangeset& set2);
45 long     CountSites(rangeset rset);
46 long     CountLinks(const rangeset& sites);
47 rangeset TargetLinksFrom(const rangeset& targetsites);
48 rangeset AddToRangeset(const rangeset& rset, long offset);
49 rangeset SubtractFromRangeset(const rangeset& rset, long offset);
50 
51 // We cannot do this since 0 target links are ambiguous as to whether they indicated
52 // 0 or 1 target sites.
53 // rangeset TargetSitesFromLinks(const rangeset& targetlinks);
54 
55 bool     IsInRangeset(const rangeset& targetrange, long target);
56 
57 // Are there sites in targetrange on both sides of target?
58 bool     Surrounds(const rangeset& targetrange, long target);
59 
60 long ToSequentialIfNeeded(long input);
61 long ToNoZeroesIfNeeded(long input);
62 rangepair ToSequentialIfNeeded(rangepair input);
63 rangepair ToNoZeroesIfNeeded(rangepair input);
64 
65 bool IsRangeCompact(const rangeset& rset);
66 #endif // RANGEX_H
67 
68 //____________________________________________________________________________________
69