/usr/include/seqan/misc/misc_dequeue.h is in seqan-dev 1.3.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | // ==========================================================================
// SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2010, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Knut Reinert or the FU Berlin nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
#ifndef SEQAN_HEADER_MISC_DEQUEUE_H
#define SEQAN_HEADER_MISC_DEQUEUE_H
#include <algorithm>
#include <seqan/sequence.h>
//////////////////////////////////////////////////////////////////////////////
namespace SEQAN_NAMESPACE_MAIN
{
/**
.Class.Dequeue:
..cat:Miscellaneous
..summary:A double-ended queue implementation on top of a @Class.String@.
..signature:Dequeue<TValue, TSpec>
..param.TValue:Type of the ungapped sequences.
...metafunction:Metafunction.Value
..param.TSpec:The specializing type of the underlying @Class.String@.
...metafunction:Metafunction.Spec
...default:$Alloc<>$, see @Spec.Alloc String@
..include:seqan/misc.h
*/
template <typename TValue, typename TSpec = Alloc<> >
class Dequeue
{
public:
typedef String<TValue, TSpec> TString;
typedef typename Iterator<TString, Standard>::Type TIter;
String<TValue, TSpec> data_string;
TIter data_begin; // string beginning
TIter data_end; // string end
TIter data_front; // front fifo character
TIter data_back; // back fifo character
bool data_empty; // fifo is empty
//____________________________________________________________________________
public:
inline Dequeue()
{
clear(*this);
}
};
//////////////////////////////////////////////////////////////////////////////
// Iterators
//////////////////////////////////////////////////////////////////////////////
///.Metafunction.Iterator.param.T.type:Class.Dequeue
template<typename TValue, typename TSpec>
struct Iterator<Dequeue<TValue, TSpec>, Standard>
{
typedef Iter<Dequeue<TValue, TSpec>, PositionIterator> Type;
};
template<typename TValue, typename TSpec>
struct Iterator<Dequeue<TValue, TSpec> const, Standard>
{
typedef Iter<Dequeue<TValue, TSpec> const, PositionIterator> Type;
};
template<typename TValue, typename TSpec>
struct Iterator<Dequeue<TValue, TSpec>, Rooted>
{
typedef Iter<Dequeue<TValue, TSpec>, PositionIterator> Type;
};
template<typename TValue, typename TSpec>
struct Iterator<Dequeue<TValue, TSpec> const, Rooted>
{
typedef Iter<Dequeue<TValue, TSpec> const, PositionIterator> Type;
};
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, typename TSpec>
inline bool
empty(Dequeue<TValue, TSpec> const &me)
{
return me.data_empty;
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, typename TSpec>
inline void
clear(Dequeue<TValue, TSpec> &me)
{
clear(me.data_string);
me.data_begin = begin(me.data_string, Standard());
me.data_end = end(me.data_string, Standard());
me.data_front = me.data_back = me.data_begin;
me.data_empty = true;
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, typename TSpec, typename TPos>
inline TValue &
value(Dequeue<TValue, TSpec> &me, TPos pos)
{
typedef typename Size<Dequeue<TValue, TSpec> >::Type TSize;
TSize wrap = length(me.data_string) - (me.data_front - me.data_begin);
if ((TSize)pos < wrap)
return value(me.data_front + pos);
else
return value(me.data_begin + (pos - wrap));
}
template <typename TValue, typename TSpec, typename TPos>
inline TValue const &
value(Dequeue<TValue, TSpec> const &me, TPos pos)
{
typedef typename Size<Dequeue<TValue, TSpec> >::Type TSize;
TSize wrap = length(me.data_string) - (me.data_front - me.data_begin);
if ((TSize)pos < wrap)
return value(me.data_front + pos);
else
return value(me.data_begin + (pos - wrap));
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, typename TSpec>
inline TValue &
front(Dequeue<TValue, TSpec> &me)
{
return *me.data_front;
}
template <typename TValue, typename TSpec>
inline TValue const &
front(Dequeue<TValue, TSpec> const &me)
{
return *me.data_front;
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, typename TSpec>
inline TValue &
back(Dequeue<TValue, TSpec> &me)
{
return *me.data_back;
}
template <typename TValue, typename TSpec>
inline TValue const &
back(Dequeue<TValue, TSpec> const &me)
{
return *me.data_back;
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, typename TSpec>
inline bool
popFront(Dequeue<TValue, TSpec> &me)
{
if (me.data_empty) return false;
if (me.data_front == me.data_back)
me.data_empty = true;
else
{
if (++me.data_front == me.data_end)
me.data_front = me.data_begin;
}
return true;
}
template <typename TValue, typename TSpec>
inline bool
popBack(Dequeue<TValue, TSpec> &me)
{
if (me.data_empty) return false;
if (me.data_front == me.data_back)
me.data_empty = true;
else
{
if (me.data_back == me.data_begin)
me.data_back = me.data_end;
--me.data_back;
}
return true;
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, typename TSpec>
inline void
pushFront(Dequeue<TValue, TSpec> &me, TValue const & _value)
{
typedef typename Dequeue<TValue, TSpec>::TIter TIter;
if (me.data_empty)
{
if (me.data_begin == me.data_end)
reserve(me, computeGenerousCapacity(me, length(me.data_string) + 1), Generous());
me.data_empty = false;
}
else
{
TIter new_front = me.data_front;
if (new_front == me.data_begin)
new_front = me.data_end;
--new_front;
if (new_front == me.data_back)
{
reserve(me, computeGenerousCapacity(me, length(me.data_string) + 1), Generous());
if (me.data_front == me.data_begin)
me.data_front = me.data_end;
--me.data_front;
} else
me.data_front = new_front;
}
assign(*me.data_front, _value);
}
template <typename TValue, typename TSpec>
inline void
pushBack(Dequeue<TValue, TSpec> &me, TValue const & _value)
{
typedef typename Dequeue<TValue, TSpec>::TIter TIter;
if (me.data_empty)
{
if (me.data_begin == me.data_end)
reserve(me, computeGenerousCapacity(me, length(me.data_string) + 1), Generous());
me.data_empty = false;
}
else
{
TIter new_back = me.data_back;
if (++new_back == me.data_end)
new_back = me.data_begin;
if (new_back == me.data_front)
{
reserve(me, computeGenerousCapacity(me, length(me.data_string) + 1), Generous());
// in this case reserve adds new space behind data_back
++me.data_back;
} else
me.data_back = new_back;
}
assign(*me.data_back, _value);
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, typename TSpec>
inline typename Size<Dequeue<TValue, TSpec> >::Type
length(Dequeue<TValue, TSpec> const &me)
{
if (empty(me)) return 0;
if (me.data_front <= me.data_back)
return (me.data_back - me.data_front) + 1;
else
return (me.data_end - me.data_begin) - (me.data_front - me.data_back) + 1;
}
//////////////////////////////////////////////////////////////////////////////
template <typename TValue, typename TSpec, typename TSize_, typename TExpand>
inline typename Size<Dequeue<TValue, TSpec> >::Type
reserve(Dequeue<TValue, TSpec> &me, TSize_ new_capacity, Tag<TExpand> const tag)
{
typedef typename Size<Dequeue<TValue, TSpec> >::Type TSize;
// ::std::cout << "resize to "<<new_capacity<<::std::endl;
TSize len = length(me);
if (len < new_capacity && length(me.data_string) != new_capacity)
{
TSize pos_front = me.data_front - me.data_begin;
TSize pos_back = me.data_back - me.data_begin;
TSize new_freeSpace = new_capacity - len;
if (pos_front <= pos_back)
{
// |empty|data|empty|
// 0
TSize freeSpace = length(me.data_string) - len;
if (new_freeSpace > freeSpace)
resize(me.data_string, new_capacity, tag);
else
{
freeSpace -= new_freeSpace; // reduce the free space by <freeSpace>
if (pos_front >= freeSpace)
{
resizeSpace(me.data_string, pos_front - freeSpace, (TSize)0, pos_front, tag);
pos_back -= freeSpace;
pos_front -= freeSpace;
}
else
{
freeSpace -= pos_front;
resizeSpace(me.data_string, length(me.data_string) - freeSpace, pos_back + 1, length(me.data_string), tag);
resizeSpace(me.data_string, (TSize)0, (TSize)0, pos_front, tag);
pos_back -= pos_front;
pos_front = 0;
}
}
}
else
{
// |data|empty|data|
// 0
resizeSpace(me.data_string, new_freeSpace, pos_back + 1, pos_front, tag);
pos_front += new_freeSpace;
}
me.data_begin = begin(me.data_string, Standard());
me.data_end = end(me.data_string, Standard());
me.data_front = me.data_begin + pos_front;
me.data_back = me.data_begin + pos_back;
}
return length(me.data_string);
}
}
#endif
|