@@ -540,12 +540,124 @@ public:
540540 }
541541};
542542
543+
544+ class FNVKmerHashIterator : public KmerHashIterator
545+ {
546+ const char * _seq;
547+ const char _ksize;
548+ unsigned int index;
549+ unsigned int length;
550+ bool _initialized;
551+ public:
552+ FNVKmerHashIterator (const char * seq, unsigned char k) :
553+ _seq (seq), _ksize(k), index(0 ), _initialized(false )
554+ {
555+ length = strlen (_seq);
556+ };
557+
558+ HashIntoType first ()
559+ {
560+ _initialized = true ;
561+ return next ();
562+ }
563+
564+ HashIntoType next ()
565+ {
566+ if (!_initialized) {
567+ _initialized = true ;
568+ }
569+
570+ if (done ()) {
571+ throw oxli_exception (" past end of iterator" );
572+ }
573+
574+ std::string kmer;
575+ kmer.assign (_seq + index, _ksize);
576+ index += 1 ;
577+ return _hash_fnv (kmer, _ksize);
578+ }
579+
580+ bool done () const
581+ {
582+ return (index + _ksize > length);
583+ }
584+
585+ unsigned int get_start_pos () const
586+ {
587+ if (!_initialized) {
588+ return 0 ;
589+ }
590+ return index - 1 ;
591+ }
592+ unsigned int get_end_pos () const
593+ {
594+ if (!_initialized) {
595+ return _ksize;
596+ }
597+ return index + _ksize - 1 ;
598+ }
599+ };
600+
601+
602+ class FNVHashtable : public oxli ::Hashtable
603+ {
604+ public:
605+ explicit FNVHashtable (WordLength ksize, Storage * s)
606+ : Hashtable(ksize, s) { };
607+
608+ inline
609+ virtual
610+ HashIntoType
611+ hash_dna (const char * kmer) const
612+ {
613+ if (!(strlen (kmer) >= _ksize)) {
614+ throw oxli_value_exception (" Supplied kmer string doesn't match the underlying k-size." );
615+ }
616+ return _hash_fnv (kmer, _ksize);
617+ }
618+
619+ inline virtual HashIntoType
620+ hash_dna_top_strand (const char * kmer) const
621+ {
622+ throw oxli_value_exception (" not implemented" );
623+ }
624+
625+ inline virtual HashIntoType
626+ hash_dna_bottom_strand (const char * kmer) const
627+ {
628+ throw oxli_value_exception (" not implemented" );
629+ }
630+
631+ inline virtual std::string
632+ unhash_dna (HashIntoType hashval) const
633+ {
634+ throw oxli_value_exception (" not implemented" );
635+ }
636+
637+ virtual KmerHashIteratorPtr new_kmer_iterator (const char * sp) const
638+ {
639+ KmerHashIterator * ki = new FNVKmerHashIterator (sp, _ksize);
640+ return unique_ptr<KmerHashIterator>(ki);
641+ }
642+
643+ virtual void save (std::string filename)
644+ {
645+ store->save (filename, _ksize);
646+ }
647+ virtual void load (std::string filename)
648+ {
649+ store->load (filename, _ksize);
650+ _init_bitstuff ();
651+ }
652+ };
653+
654+
543655// Hashtable-derived class with ByteStorage.
544- class Counttable : public oxli ::MurmurHashtable
656+ class Counttable : public oxli ::FNVHashtable
545657{
546658public:
547659 explicit Counttable (WordLength ksize, std::vector<uint64_t > sizes)
548- : MurmurHashtable (ksize, new ByteStorage(sizes)) { } ;
660+ : FNVHashtable (ksize, new ByteStorage(sizes)) { } ;
549661};
550662
551663// Hashtable-derived class with NibbleStorage.
0 commit comments