VwNativeCacheReader.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009 Yahoo! Inc.  All rights reserved.  The copyrights
00003  * embodied in the content of this file are licensed under the BSD
00004  * (revised) open source license.
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 3 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * Written (W) 2011 Shashwat Lal Das
00012  * Adaptation of Vowpal Wabbit v5.1.
00013  * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society.
00014  */
00015 
00016 #ifndef _VW_NATIVECACHE_READ_H__
00017 #define _VW_NATIVECACHE_READ_H__
00018 
00019 #include <shogun/classifier/vw/cache/VwCacheReader.h>
00020 
00021 namespace shogun
00022 {
00023 
00024 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00025 // Packed structure for efficient storage
00026 struct one_float
00027 {
00028     // The float to store
00029     float32_t f;
00030 } __attribute__((packed));
00031 
00032 #endif // DOXYGEN_SHOULD_SKIP_THIS
00033 
00039 class CVwNativeCacheReader: public CVwCacheReader
00040 {
00041 public:
00045     CVwNativeCacheReader();
00046 
00053     CVwNativeCacheReader(char * fname, CVwEnvironment* env_to_use);
00054 
00061     CVwNativeCacheReader(int32_t f, CVwEnvironment* env_to_use);
00062 
00066     virtual ~CVwNativeCacheReader();
00067 
00073     virtual void set_file(int32_t f);
00074 
00080     virtual bool read_cached_example(VwExample* const ae);
00081 
00085     void check_cache_metadata();
00086 
00092     virtual const char* get_name() const { return "VwNativeCacheReader"; }
00093 
00094 private:
00098     void init();
00099 
00108     char* run_len_decode(char *p, vw_size_t& i);
00109 
00117     inline int32_t ZigZagDecode(uint32_t n)
00118     {
00119         return (n >> 1) ^ -static_cast<int32_t>(n & 1);
00120     }
00121 
00130     char* bufread_label(VwLabel* const ld, char* c);
00131 
00139     vw_size_t read_cached_label(VwLabel* const ld);
00140 
00148     vw_size_t read_cached_tag(VwExample* const ae);
00149 
00150 
00151 protected:
00153     CIOBuffer buf;
00154 
00155 private:
00156     // Used while parsing
00157     const vw_size_t int_size;
00158     const vw_size_t char_size;
00159     vw_size_t neg_1;
00160     vw_size_t general;
00161 };
00162 
00163 }
00164 #endif // _VW_NATIVECACHE_READ_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation