1 /*==========================================================================
2 SeqAn - The Library for Sequence Analysis
4 ============================================================================
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 3 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 ============================================================================
18 $Id: string_packed.h,v 1.2 2009/02/19 01:51:23 langmead Exp $
19 ==========================================================================*/
21 #ifndef SEQAN_HEADER_SEQUENCE_PACKED_H
22 #define SEQAN_HEADER_SEQUENCE_PACKED_H
25 namespace SEQAN_NAMESPACE_MAIN
28 //////////////////////////////////////////////////////////////////////////////
30 //////////////////////////////////////////////////////////////////////////////
32 template <typename THostspec = Alloc<> >
36 //////////////////////////////////////////////////////////////////////////////
40 ..general:Class.String
41 ..summary:A string that stores as many values in one machine word as possible.
42 ..signature:String<TValue, Packed<THostspec> >
43 ..param.TValue:The value type, that is the type of the items/characters stored in the string.
44 ...remarks:Use @Metafunction.Value@ to get the value type for a given class.
45 ..param.THostspec:The specializing type.
46 ...remarks:This is the specialization of the host string that is used for storing the packed values.
47 ...default:@Spec.Alloc String.Alloc<>@
50 /*???TODO Optimierungsmöglichkeiten:
51 - _clearSpace kopiert Zeichenweise im Packed-String, und nicht im Host-String
52 - _clearSpace verwendet resize, um den Host zu vergrößern, d.h. der Inhalt wird eventuell doppelt kopiert.
55 //////////////////////////////////////////////////////////////////////////////
56 //Rooted expandable string
57 //////////////////////////////////////////////////////////////////////////////
59 template <typename TValue, typename THostspec>
60 class String<TValue, Packed<THostspec> >
63 typedef typename Host<String>::Type THost;
64 typedef typename Size<String>::Type TSize;
69 //____________________________________________________________________________
78 template <typename TSource>
79 String(TSource & source):
83 assign(*this, source);
85 template <typename TSource>
86 String(TSource const & source):
90 assign(*this, source);
92 String(String const & source):
96 assign(*this, source);
99 template <typename TSource>
100 String & operator =(TSource const & source)
103 assign(*this, source);
106 String & operator =(String const & source)
109 assign(*this, source);
119 //____________________________________________________________________________
121 template <typename TPos>
122 inline typename Reference<String>::Type
123 operator [] (TPos pos)
126 return value(*this, pos);
129 template <typename TPos>
130 inline typename Reference<String const>::Type
131 operator [] (TPos pos) const
134 return value(*this, pos);
137 //____________________________________________________________________________
139 ///.Function.host.param.object.type:Spec.Packed String
141 friend inline THost &
148 friend inline THost const &
149 host(String const & me)
155 //____________________________________________________________________________
161 return me.data_length;
165 length(String const & me)
168 return me.data_length;
171 //____________________________________________________________________________
179 me.data_length = new_length;
180 _setLength(host(me), _PackedConsts<String>::toHostLength(new_length));
183 //____________________________________________________________________________
186 //////////////////////////////////////////////////////////////////////////////
188 template <typename TValue, typename THostspec>
189 struct DefaultOverflowImplicit<String<TValue, Packed<THostspec> > >:
190 DefaultOverflowImplicit< typename Host<String<TValue, Packed<THostspec> > >::Type >
193 template <typename TValue, typename THostspec>
194 struct DefaultOverflowImplicit<String<TValue, Packed<THostspec> > const>:
195 DefaultOverflowImplicit< typename Host<String<TValue, Packed<THostspec> > const>::Type >
199 //////////////////////////////////////////////////////////////////////////////
201 template <typename TValue, typename THostspec>
202 struct DefaultOverflowExplicit<String<TValue, Packed<THostspec> > >:
203 DefaultOverflowExplicit< typename Host<String<TValue, Packed<THostspec> > >::Type >
206 template <typename TValue, typename THostspec>
207 struct DefaultOverflowExplicit<String<TValue, Packed<THostspec> > const>:
208 DefaultOverflowExplicit< typename Host<String<TValue, Packed<THostspec> > const>::Type >
212 //////////////////////////////////////////////////////////////////////////////
214 template <typename TValue, typename THostspec>
215 struct IsContiguous<String<TValue, Packed<THostspec> > >
218 enum { VALUE = false };
221 //////////////////////////////////////////////////////////////////////////////
223 ///.Metafunction.Host.param.T.type:Spec.Packed String
225 template <typename TValue, typename THostspec>
226 struct Host<String<TValue, Packed<THostspec> > >
228 typedef String<unsigned int, THostspec> Type;
230 template <typename TValue, typename THostspec>
231 struct Host<String<TValue, Packed<THostspec> > const>
233 typedef String<unsigned int, THostspec> const Type;
236 //////////////////////////////////////////////////////////////////////////////
238 template <typename TValue, typename THostspec>
239 struct GetValue<String<TValue, Packed<THostspec> > >:
240 Value<String<TValue, Packed<THostspec> > >
243 template <typename TValue, typename THostspec>
244 struct GetValue<String<TValue, Packed<THostspec> > const>:
245 Value<String<TValue, Packed<THostspec> > const>
249 //////////////////////////////////////////////////////////////////////////////
251 template <typename TValue, typename THostspec>
252 struct Reference<String<TValue, Packed<THostspec> > >
254 typedef typename Iterator<String<TValue, Packed<THostspec> >, Standard>::Type TIterator;
255 typedef Proxy<IteratorProxy<TIterator> > Type;
257 template <typename TValue, typename THostspec>
258 struct Reference<String<TValue, Packed<THostspec> > const>
260 typedef typename Iterator<String<TValue, Packed<THostspec> > const, Standard>::Type TIterator;
261 typedef Proxy<IteratorProxy<TIterator> > Type;
264 //////////////////////////////////////////////////////////////////////////////
266 template <typename TValue, typename THostspec>
267 struct Size<String<TValue, Packed<THostspec> > >
269 typedef __int64 Type;
271 template <typename TValue, typename THostspec>
272 struct Size<String<TValue, Packed<THostspec> > const>
274 typedef __int64 Type;
278 //////////////////////////////////////////////////////////////////////////////
279 //////////////////////////////////////////////////////////////////////////////
280 // Compute Bit Values
281 //////////////////////////////////////////////////////////////////////////////
283 template <typename TPackedContainer>
286 typedef typename Value<TPackedContainer>::Type TValue;
287 typedef typename Host<TPackedContainer>::Type THost;
288 typedef typename Value<THost>::Type THostValue;
292 BITS_PER_VALUE = BitsPerValue<TValue>::VALUE,
293 BITS_PER_HOST_VALUE = BitsPerValue<THostValue>::VALUE,
294 VALUES_PER_WORD = (BITS_PER_VALUE > BITS_PER_HOST_VALUE) ? 1 : (BITS_PER_HOST_VALUE / BITS_PER_VALUE),
295 VALUE_MASK = (1 << BITS_PER_VALUE) - 1,
296 MAX_BIT_POS = (VALUES_PER_WORD - 1) * BITS_PER_VALUE
299 static typename Size<THost>::Type
300 toHostLength(typename Size<TPackedContainer>::Type len)
302 return (len + VALUES_PER_WORD - 1) / VALUES_PER_WORD;
306 //////////////////////////////////////////////////////////////////////////////
307 //////////////////////////////////////////////////////////////////////////////
309 //////////////////////////////////////////////////////////////////////////////
310 //note: this works only, if the copy assignment is done without using _TempCopy
312 template <typename TValue, typename THostspec>
313 struct _TempCopy<String<TValue, Packed<THostspec> > >
315 typedef String<TValue, Packed<THostspec> > Type;
318 //////////////////////////////////////////////////////////////////////////////
319 //optimized variant for copy assignment. The host sequence is copied instead of
320 //copying the packed string value by value
322 template <typename TTarget, typename TSource, typename TTag>
324 _assign_copy_packed_string(TTarget & target,
328 typedef typename Size<TTarget>::Type TSize2;
330 assign(host(target), host(source), tag);
331 TSize2 new_length_limit = length(host(target)) * _PackedConsts<TTarget>::VALUES_PER_WORD;
332 TSize2 new_length = length(source);
333 if (new_length > new_length_limit)
335 new_length = new_length_limit;
337 _setLength(target, new_length);
339 template <typename TTarget, typename TSource, typename TSize, typename TTag>
341 _assign_copy_packed_string(TTarget & target,
346 typedef typename Size<TTarget>::Type TSize2;
348 TSize2 host_limit = _PackedConsts<TTarget>::toHostLength(limit);
349 assign(host(target), host(source), host_limit, tag);
350 TSize2 new_length_limit = length(host(target)) * _PackedConsts<TTarget>::VALUES_PER_WORD;
351 TSize2 new_length = length(source);
352 if (new_length > new_length_limit)
354 new_length = new_length_limit;
356 if (new_length > limit)
360 _setLength(target, new_length);
362 //____________________________________________________________________________
364 template <typename TValue, typename THostspec, typename TTag>
366 assign(String<TValue, Packed<THostspec> > & target,
367 String<TValue, Packed<THostspec> > & source,
370 _assign_copy_packed_string(target, source, tag);
372 template <typename TValue, typename THostspec, typename TTag>
374 assign(String<TValue, Packed<THostspec> > & target,
375 String<TValue, Packed<THostspec> > const & source,
378 _assign_copy_packed_string(target, source, tag);
381 template <typename TValue, typename THostspec, typename TSize, typename TTag>
382 void assign(String<TValue, Packed<THostspec> > & target,
383 String<TValue, Packed<THostspec> > & source,
387 _assign_copy_packed_string(target, source, limit, tag);
389 template <typename TValue, typename THostspec, typename TSize, typename TTag>
390 void assign(String<TValue, Packed<THostspec> > & target,
391 String<TValue, Packed<THostspec> > const & source,
395 _assign_copy_packed_string(target, source, limit, tag);
398 //////////////////////////////////////////////////////////////////////////////
399 //////////////////////////////////////////////////////////////////////////////
401 //////////////////////////////////////////////////////////////////////////////
403 template <typename TValue, typename THostspec>
405 id(String<TValue, Packed<THostspec> > const & me)
411 //////////////////////////////////////////////////////////////////////////////
413 template <typename TValue, typename THostspec, typename TPos, typename TTag>
414 inline typename Iterator<String<TValue, Packed<THostspec> >, Tag<TTag> const>::Type
415 iter(String<TValue, Packed<THostspec> > & me,
420 typedef typename Iterator<String<TValue, Packed<THostspec> >, Tag<TTag> const>::Type TIterator;
421 return TIterator(me, pos_);
423 template <typename TValue, typename THostspec, typename TPos, typename TTag>
424 inline typename Iterator<String<TValue, Packed<THostspec> > const, Tag<TTag> const>::Type
425 iter(String<TValue, Packed<THostspec> > const & me,
430 typedef typename Iterator<String<TValue, Packed<THostspec> > const, Tag<TTag> const>::Type TIterator;
431 return TIterator(me, pos_);
434 //////////////////////////////////////////////////////////////////////////////
436 template <typename TValue, typename THostspec, typename TTag>
437 inline typename Iterator<String<TValue, Packed<THostspec> >, Tag<TTag> const>::Type
438 begin(String<TValue, Packed<THostspec> > & me,
439 Tag<TTag> const tag_)
442 return iter(me, 0, tag_);
444 template <typename TValue, typename THostspec, typename TTag>
445 inline typename Iterator<String<TValue, Packed<THostspec> > const, Tag<TTag> const>::Type
446 begin(String<TValue, Packed<THostspec> > const & me,
447 Tag<TTag> const tag_)
450 return iter(me, 0, tag_);
453 //////////////////////////////////////////////////////////////////////////////
455 //////////////////////////////////////////////////////////////////////////////
457 template <typename TValue, typename THostspec, typename TTag>
458 inline typename Iterator<String<TValue, Packed<THostspec> >, Tag<TTag> const>::Type
459 end(String<TValue, Packed<THostspec> > & me,
460 Tag<TTag> const tag_)
463 return iter(me, length(me), tag_);
465 template <typename TValue, typename THostspec, typename TTag>
466 inline typename Iterator<String<TValue, Packed<THostspec> > const, Tag<TTag> const>::Type
467 end(String<TValue, Packed<THostspec> > const & me,
468 Tag<TTag> const tag_)
471 return iter(me, length(me), tag_);
474 //////////////////////////////////////////////////////////////////////////////
476 //////////////////////////////////////////////////////////////////////////////
478 template <typename TValue, typename THostspec, typename TPos>
479 inline typename Reference<String<TValue, Packed<THostspec> > >::Type
480 value(String<TValue, Packed<THostspec> > & me,
485 return *iter(me, pos, Standard());
487 template <typename TValue, typename THostspec, typename TPos>
488 inline typename Reference<String<TValue, Packed<THostspec> > const>::Type
489 value(String<TValue, Packed<THostspec> > const & me,
494 return *iter(me, pos, Standard());
498 //////////////////////////////////////////////////////////////////////////////
500 //////////////////////////////////////////////////////////////////////////////
502 template <typename TValue, typename THostspec>
503 inline typename Size<String<TValue, Packed<THostspec> > const>::Type
504 capacity(String<TValue, Packed<THostspec> > const & me)
507 typedef typename Size<String<TValue, Packed<THostspec> > const>::Type TSize;
508 TSize len = capacity(host(me));
509 len *= _PackedConsts<String<TValue, Packed<THostspec> > >::VALUES_PER_WORD;
513 //////////////////////////////////////////////////////////////////////////////
515 //////////////////////////////////////////////////////////////////////////////
517 template <typename TValue, typename THostspec>
519 clear(String<TValue, Packed<THostspec> > & me)
526 //////////////////////////////////////////////////////////////////////////////
528 //////////////////////////////////////////////////////////////////////////////
530 //implementation for all expand tags other than "limit"
531 template <typename TExpand>
532 struct _ClearSpace_String_Packed_
534 template <typename T>
535 static inline typename Size<T>::Type
538 typename Size<T>::Type size)
541 typedef typename Size<T>::Type TSize;
542 TSize wanted_host_length = _PackedConsts<T>::toHostLength(size);
543 TSize new_host_length = resize(host(seq), wanted_host_length, TExpand());
544 if (new_host_length < wanted_host_length)
546 size = new_host_length * _PackedConsts<T>::VALUES_PER_WORD;
548 _setLength(seq, size);
552 template <typename T>
553 static inline typename Size<T>::Type
556 typename Size<T>::Type size,
557 typename Size<T>::Type limit)
564 return _clearSpace_(seq, limit);
567 template <typename T>
568 static inline typename Size<T>::Type
571 typename Size<T>::Type size,
572 typename Size<T>::Type start,
573 typename Size<T>::Type end)
576 return _clearSpace_(seq, size, start, end, supremumValue<typename Size<T>::Type >());
579 template <typename T>
580 static typename Size<T>::Type
583 typename Size<T>::Type size,
584 typename Size<T>::Type start,
585 typename Size<T>::Type end,
586 typename Size<T>::Type limit)
589 //??? TODO: This function can be accelerated this way:
590 // - move values in host
591 // - avoid double moving of the rest-part if "resize" allocates a new block
593 typedef typename Size<T>::Type TSize;
594 typedef typename Iterator<T, Standard>::Type TIterator;
596 TSize old_length = length(seq);
597 TSize old_size = end - start;
598 TSize wanted_new_length = old_length + size - old_size;
600 if (wanted_new_length > limit)
602 wanted_new_length = limit;
605 TSize wanted_host_length = _PackedConsts<T>::toHostLength(wanted_new_length);
606 TSize new_host_length = resize(host(seq), wanted_host_length, TExpand());
609 if (new_host_length < wanted_host_length)
611 new_length = new_host_length * _PackedConsts<T>::VALUES_PER_WORD;
612 if (new_length <= start + size)
616 old_length = new_length - size + old_size;
620 new_length = wanted_new_length;
623 //move [end:right_end] to [start + size:..]
626 ::std::copy_backward(iter(seq, end, Standard()), iter(seq, old_length, Standard()), iter(seq, new_length, Standard()));
629 {//move rest to right
630 ::std::copy(iter(seq, end, Standard()), iter(seq, old_length, Standard()), iter(seq, end + size - old_size, Standard()));
633 _setLength(seq, new_length);
637 template <typename T>
638 static inline typename Size<T>::Type
641 typename Size<T>::Type size,
642 typename Iterator<T>::Type start,
643 typename Iterator<T>::Type end)
646 typename Iterator<T>::Type seq_begin = begin(seq);
647 return _clearSpace(seq, size, start - seq_begin, end - seq_begin, Insist());
650 template <typename T>
651 static inline typename Size<T>::Type
654 typename Size<T>::Type size,
655 typename Iterator<T>::Type start,
656 typename Iterator<T>::Type end,
657 typename Size<T>::Type limit)
660 typename Iterator<T>::Type seq_begin = begin(seq);
661 return _clearSpace(seq, size, start - seq_begin, end - seq_begin, limit, Insist());
666 //////////////////////////////////////////////////////////////////////////////
668 template<typename TValue, typename THostspec, typename TExpand>
669 inline typename Size< String<TValue, Packed<THostspec> > >::Type
670 _clearSpace(String<TValue, Packed<THostspec> > & me,
671 typename Size< String<TValue, Packed<THostspec> > >::Type size,
675 return _ClearSpace_String_Packed_<Tag<TExpand> const>::_clearSpace_(me, size);
678 template<typename TValue, typename THostspec, typename TExpand>
679 inline typename Size< String<TValue, Packed<THostspec> > >::Type
680 _clearSpace(String<TValue, Packed<THostspec> > & me,
681 typename Size< String<TValue, Packed<THostspec> > >::Type size,
682 typename Size< String<TValue, Packed<THostspec> > >::Type limit,
686 return _ClearSpace_String_Packed_<Tag<TExpand> const>::_clearSpace_(me, size, limit);
689 template<typename TValue, typename THostspec, typename TPosition, typename TExpand>
690 inline typename Size< String<TValue, Packed<THostspec> > >::Type
691 _clearSpace(String<TValue, Packed<THostspec> > & me,
692 typename Size< String<TValue, Packed<THostspec> > >::Type size,
698 return _ClearSpace_String_Packed_<Tag<TExpand> const>::_clearSpace_(me, size, pos_begin, pos_end);
701 template<typename TValue, typename THostspec, typename TPosition, typename TExpand>
702 inline typename Size< String<TValue, Packed<THostspec> > >::Type
703 _clearSpace(String<TValue, Packed<THostspec> > & me,
704 typename Size< String<TValue, Packed<THostspec> > >::Type size,
707 typename Size< String<TValue, Packed<THostspec> > >::Type limit,
711 return _ClearSpace_String_Packed_<Tag<TExpand> const>::_clearSpace_(me, size, pos_begin, pos_end, limit);
715 //////////////////////////////////////////////////////////////////////////////
718 ///.Function.reserve.param.object.type:Spec.Packed String
720 template <typename TValue, typename TSpec, typename _TSize, typename TExpand>
721 inline typename Size< String<TValue, Packed<TSpec> > >::Type
723 String<TValue, Packed<TSpec> > & seq,
725 Tag<TExpand> const tag)
729 typedef String<TValue, Packed<TSpec> > TString;
730 typedef typename Size<TString>::Type TSize;
731 TSize ret_value = reserve(host(seq), _PackedConsts<TString>::toHostLength(new_capacity), tag);
732 return ret_value * _PackedConsts<TString>::VALUES_PER_WORD;
735 template <typename TValue, typename TSpec, typename _TSize>
736 inline typename Size< String<TValue, Alloc<TSpec> > >::Type
738 String<TValue, Packed<TSpec> > & me,
743 typedef typename Size< String<TValue, Alloc<TSpec> > >::Type TSize;
745 TSize me_capacity = capacity(me);
746 if (me_capacity < (TSize)new_capacity) return me_capacity;
750 template <typename TValue, typename TSpec, typename _TSize>
751 inline typename Size< String<TValue, Alloc<TSpec> > >::Type
753 String<TValue, Packed<TSpec> > & me,
758 typedef typename Size< String<TValue, Alloc<TSpec> > >::Type TSize;
764 //////////////////////////////////////////////////////////////////////////////
765 //////////////////////////////////////////////////////////////////////////////
767 //////////////////////////////////////////////////////////////////////////////
769 template <typename TValue, typename THostspec, typename TSpec>
770 struct Iterator<String<TValue, Packed<THostspec> >, TSpec>
772 typedef Iter<String<TValue, Packed<THostspec> >, Packed<THostspec> > Type;
774 template <typename TValue, typename THostspec, typename TSpec>
775 struct Iterator<String<TValue, Packed<THostspec> > const, TSpec>
777 typedef Iter<String<TValue, Packed<THostspec> > const, Packed<THostspec> > Type;
780 //////////////////////////////////////////////////////////////////////////////
781 //////////////////////////////////////////////////////////////////////////////
782 // Iterator for packed strings
783 //////////////////////////////////////////////////////////////////////////////
785 template <typename TContainer, typename THostspec>
786 class Iter<TContainer, Packed<THostspec> >
789 typedef typename Host<TContainer>::Type THost;
790 typedef typename Iterator<THost, Standard>::Type THostIterator;
791 typedef typename Position<TContainer>::Type TPosition;
793 typename _Pointer<TContainer>::Type data_container;
794 THostIterator data_iterator;
795 unsigned char data_bitpos;
797 //____________________________________________________________________________
804 Iter(typename _Parameter<TContainer>::Type container_):
805 data_container(_toPointer(container_)),
806 data_iterator(begin(host(container_))),
811 Iter(typename _Parameter<TContainer>::Type container_, TPosition pos_):
812 data_container(_toPointer(container_))
815 setPosition(*this, pos_);
817 Iter(Iter const & other_):
818 data_container(other_.data_container),
819 data_iterator(other_.data_iterator),
820 data_bitpos(other_.data_bitpos)
829 operator = (Iter const & other_)
832 data_container = other_.data_container;
833 data_iterator = other_.data_iterator;
834 data_bitpos = other_.data_bitpos;
837 //____________________________________________________________________________
839 friend inline typename _Parameter<TContainer>::Type
843 return _toParameter<TContainer>(me.data_container);
845 friend inline typename _Parameter<TContainer>::Type
846 container(Iter const & me)
849 return _toParameter<TContainer>(me.data_container);
851 //____________________________________________________________________________
854 setContainer(Iter & me, typename _Parameter<TContainer>::Type container_)
857 typename Position<Iter>::Type pos = position(me);
858 me.data_container = _toPointer(container_);
859 setPosition(me, pos);
862 //____________________________________________________________________________
864 friend inline THostIterator &
865 hostIterator(Iter & me)
868 return me.data_iterator;
870 friend inline THostIterator const &
871 hostIterator(Iter const & me)
874 return me.data_iterator;
877 //____________________________________________________________________________
879 friend inline unsigned char &
883 return me.data_bitpos;
885 friend inline unsigned char
886 _bitpos(Iter const & me)
889 return me.data_bitpos;
892 //____________________________________________________________________________
895 //////////////////////////////////////////////////////////////////////////////
897 //////////////////////////////////////////////////////////////////////////////
899 template <typename TContainer, typename THostspec>
900 inline typename Position<Iter<TContainer, Packed<THostspec> > const>::Type
901 position(Iter<TContainer, Packed<THostspec> > const & me)
904 typedef typename Host<TContainer>::Type THost;
905 THost const & host_ = host(container(me));
906 return (hostIterator(me) - begin(host_)) * _PackedConsts<TContainer>::VALUES_PER_WORD + _bitpos(me) / _PackedConsts<TContainer>::BITS_PER_VALUE;
909 //////////////////////////////////////////////////////////////////////////////
911 //////////////////////////////////////////////////////////////////////////////
913 template <typename TContainer, typename THostspec, typename TPosition>
915 setPosition(Iter<TContainer, Packed<THostspec> > & me,
919 hostIterator(me) = begin(host(container(me))) + pos_ / _PackedConsts<TContainer>::VALUES_PER_WORD;
920 _bitpos(me) = (pos_ % _PackedConsts<TContainer>::VALUES_PER_WORD) * _PackedConsts<TContainer>::BITS_PER_VALUE;
923 //////////////////////////////////////////////////////////////////////////////
925 //////////////////////////////////////////////////////////////////////////////
927 template <typename TContainer, typename THostspec>
928 inline typename Reference<Iter<TContainer, Packed<THostspec> > >::Type
929 value(Iter<TContainer, Packed<THostspec> > & me)
932 return typename Reference<Iter<TContainer, Packed<THostspec> > >::Type(me);
934 template <typename TContainer, typename THostspec>
935 inline typename Reference<Iter<TContainer, Packed<THostspec> > const>::Type
936 value(Iter<TContainer, Packed<THostspec> > const & me)
939 return typename Reference<Iter<TContainer, Packed<THostspec> > const>::Type(me);
942 //////////////////////////////////////////////////////////////////////////////
944 //////////////////////////////////////////////////////////////////////////////
946 template <typename TContainer, typename THostspec>
947 inline typename GetValue<Iter<TContainer, Packed<THostspec> > >::Type
948 getValue(Iter<TContainer, Packed<THostspec> > & me)
951 return (value(hostIterator(me)) >> _bitpos(me)) & _PackedConsts<TContainer>::VALUE_MASK;
953 template <typename TContainer, typename THostspec>
954 inline typename GetValue<Iter<TContainer, Packed<THostspec> > const>::Type
955 getValue(Iter<TContainer, Packed<THostspec> > const & me)
958 return (value(hostIterator(me)) >> _bitpos(me)) & _PackedConsts<TContainer>::VALUE_MASK;
961 /////////////////////////////////////////////////////////////////////////////
963 //////////////////////////////////////////////////////////////////////////////
965 template <typename TIter, typename TValue>
967 _assignValue_packed_string_iterator(TIter & me,
970 typedef typename Container<TIter>::Type TContainer;
971 typedef typename Host<TContainer>::Type THost;
972 typedef typename Value<THost>::Type THostValue;
973 THostValue mask_ = _PackedConsts<TContainer>::VALUE_MASK << _bitpos(me);
974 THostValue val_ = _value;
975 val_ <<= _bitpos(me);
977 assignValue(hostIterator(me), (getValue(hostIterator(me)) & ~(mask_)) | val_);
981 template <typename TContainer, typename THostspec, typename TValue>
983 assignValue(Iter<TContainer, Packed<THostspec> > & me,
984 TValue const & _value)
987 typedef Iter<TContainer, Packed<THostspec> > TIterator;
988 typename Value<TIterator>::Type _temp_value = _value; //conversion
989 _assignValue_packed_string_iterator(me, _temp_value);
991 template <typename TContainer, typename THostspec, typename TValue>
993 assignValue(Iter<TContainer, Packed<THostspec> > const & me,
994 TValue const & _value)
997 typedef Iter<TContainer, Packed<THostspec> > const TIterator;
998 typename Value<TIterator>::Type _temp_value = _value; //conversion
999 _assignValue_packed_string_iterator(me, _temp_value);
1002 /////////////////////////////////////////////////////////////////////////////
1004 //////////////////////////////////////////////////////////////////////////////
1006 template <typename TContainer, typename THostspec, typename TValue>
1008 moveValue(Iter<TContainer, Packed<THostspec> > & me,
1009 TValue const & _value)
1012 assignValue(me, _value);
1014 template <typename TContainer, typename THostspec, typename TValue>
1016 moveValue(Iter<TContainer, Packed<THostspec> > const & me,
1017 TValue const & _value)
1020 assignValue(me, _value);
1023 //////////////////////////////////////////////////////////////////////////////
1025 //////////////////////////////////////////////////////////////////////////////
1026 //emulate construction and destruction
1028 template <typename TContainer, typename THostspec>
1030 valueConstruct(Iter<TContainer, Packed<THostspec> > const & /*it*/)
1033 template <typename TContainer, typename THostspec, typename TParam>
1035 valueConstruct(Iter<TContainer, Packed<THostspec> > const & it,
1036 TParam const & param_)
1038 assignValue(it, param_);
1040 template <typename TContainer, typename THostspec, typename TParam>
1042 valueConstruct(Iter<TContainer, Packed<THostspec> > const & it,
1043 TParam const & param_,
1046 moveValue(it, param_);
1049 //////////////////////////////////////////////////////////////////////////////
1051 //////////////////////////////////////////////////////////////////////////////
1053 template <typename TContainer, typename THostspec>
1055 valueDestruct(Iter<TContainer, Packed<THostspec> > const & /*it*/)
1059 //////////////////////////////////////////////////////////////////////////////
1061 //////////////////////////////////////////////////////////////////////////////
1063 template <typename TContainer, typename THostspec>
1065 operator == (Iter<TContainer, Packed<THostspec> > const & left,
1066 Iter<TContainer, Packed<THostspec> > const & right)
1069 return (hostIterator(left) == hostIterator(right)) && (_bitpos(left) == _bitpos(right));
1072 //////////////////////////////////////////////////////////////////////////////
1074 //////////////////////////////////////////////////////////////////////////////
1076 template <typename TContainer, typename THostspec>
1078 operator != (Iter<TContainer, Packed<THostspec> > const & left,
1079 Iter<TContainer, Packed<THostspec> > const & right)
1082 return (hostIterator(left) != hostIterator(right)) || (_bitpos(left) != _bitpos(right));
1085 //////////////////////////////////////////////////////////////////////////////
1087 //////////////////////////////////////////////////////////////////////////////
1089 template <typename TContainer, typename THostspec>
1091 operator > (Iter<TContainer, Packed<THostspec> > const & left,
1092 Iter<TContainer, Packed<THostspec> > const & right)
1095 return (hostIterator(left) > hostIterator(right)) || ((hostIterator(left) == hostIterator(right)) && (_bitpos(left) > _bitpos(right)));
1098 //////////////////////////////////////////////////////////////////////////////
1100 //////////////////////////////////////////////////////////////////////////////
1102 template <typename TContainer, typename THostspec>
1104 operator >= (Iter<TContainer, Packed<THostspec> > const & left,
1105 Iter<TContainer, Packed<THostspec> > const & right)
1108 return (hostIterator(left) > hostIterator(right)) || ((hostIterator(left) == hostIterator(right)) && (_bitpos(left) >= _bitpos(right)));
1111 //////////////////////////////////////////////////////////////////////////////
1113 //////////////////////////////////////////////////////////////////////////////
1115 template <typename TContainer, typename THostspec>
1117 operator < (Iter<TContainer, Packed<THostspec> > const & left,
1118 Iter<TContainer, Packed<THostspec> > const & right)
1121 return (hostIterator(left) < hostIterator(right)) || ((hostIterator(left) == hostIterator(right)) && (_bitpos(left) < _bitpos(right)));
1124 //////////////////////////////////////////////////////////////////////////////
1126 //////////////////////////////////////////////////////////////////////////////
1128 template <typename TContainer, typename THostspec>
1130 operator <= (Iter<TContainer, Packed<THostspec> > const & left,
1131 Iter<TContainer, Packed<THostspec> > const & right)
1134 return (hostIterator(left) < hostIterator(right)) || ((hostIterator(left) == hostIterator(right)) && (_bitpos(left) <= _bitpos(right)));
1137 //////////////////////////////////////////////////////////////////////////////
1139 //////////////////////////////////////////////////////////////////////////////
1141 template <typename TContainer, typename THostspec>
1143 goNext(Iter<TContainer, Packed<THostspec> > & me)
1146 int new_bitpos = _bitpos(me) + _PackedConsts<TContainer>::BITS_PER_VALUE;
1147 if (new_bitpos <= _PackedConsts<TContainer>::MAX_BIT_POS)
1149 _bitpos(me) = (unsigned char) new_bitpos;
1154 goNext(hostIterator(me));
1158 //////////////////////////////////////////////////////////////////////////////
1160 //////////////////////////////////////////////////////////////////////////////
1162 template <typename TContainer, typename THostspec>
1164 goPrevious(Iter<TContainer, Packed<THostspec> > & me)
1167 int new_bitpos = _bitpos(me) - _PackedConsts<TContainer>::BITS_PER_VALUE;
1168 if (new_bitpos >= 0)
1170 _bitpos(me) = (unsigned char) new_bitpos;
1174 _bitpos(me) = _PackedConsts<TContainer>::MAX_BIT_POS;
1175 goPrevious(hostIterator(me));
1178 goPrevious(hostIterator(me));
1181 //////////////////////////////////////////////////////////////////////////////
1183 //////////////////////////////////////////////////////////////////////////////
1185 template <typename TContainer, typename THostspec, typename TIntegral>
1186 inline Iter<TContainer, Packed<THostspec> >
1187 operator + (Iter<TContainer, Packed<THostspec> > const & left,
1191 return Iter<TContainer, Packed<THostspec> >(container(left), position(left) + right);
1193 template <typename TContainer, typename THostspec, typename TIntegral>
1194 inline Iter<TContainer, Packed<THostspec> >
1195 operator + (TIntegral left,
1196 Iter<TContainer, Packed<THostspec> > const & right)
1199 return Iter<TContainer, Packed<THostspec> >(container(right), position(right) + left);
1202 //////////////////////////////////////////////////////////////////////////////
1204 //////////////////////////////////////////////////////////////////////////////
1206 template <typename TContainer, typename THostspec, typename TIntegral>
1207 inline Iter<TContainer, Packed<THostspec> > &
1208 operator += (Iter<TContainer, Packed<THostspec> > & left,
1212 setPosition(left, position(left) + right);
1216 //////////////////////////////////////////////////////////////////////////////
1218 //////////////////////////////////////////////////////////////////////////////
1220 template <typename TContainer, typename THostspec, typename TIntegral>
1221 inline Iter<TContainer, Packed<THostspec> >
1222 operator - (Iter<TContainer, Packed<THostspec> > const & left,
1226 return Iter<TContainer, AdaptorIterator<THostspec> >(container(left), position(left) - right);
1229 //____________________________________________________________________________
1231 template <typename TContainer, typename THostspec>
1232 inline typename Difference<Iter<TContainer, Packed<THostspec> > >::Type
1233 operator - (Iter<TContainer, Packed<THostspec> > const & left,
1234 Iter<TContainer, Packed<THostspec> > const & right)
1237 return position(left) - position(right);
1240 //////////////////////////////////////////////////////////////////////////////
1242 //////////////////////////////////////////////////////////////////////////////
1244 template <typename TContainer, typename THostspec, typename TIntegral>
1245 inline Iter<TContainer, Packed<THostspec> > &
1246 operator -= (Iter<TContainer, Packed<THostspec> > & left,
1250 setPosition(left, position(left) - right);
1254 //////////////////////////////////////////////////////////////////////////////
1258 //////////////////////////////////////////////////////////////////////////////
1260 } //namespace SEQAN_NAMESPACE_MAIN
1262 #endif //#ifndef SEQAN_HEADER_...