SHOGUN
v3.2.0
|
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_WRITE_H__ 00017 #define _VW_NATIVECACHE_WRITE_H__ 00018 00019 #include <shogun/classifier/vw/cache/VwCacheWriter.h> 00020 00021 namespace shogun 00022 { 00026 class CVwNativeCacheWriter: public CVwCacheWriter 00027 { 00028 public: 00032 CVwNativeCacheWriter(); 00033 00040 CVwNativeCacheWriter(char * fname, CVwEnvironment* env_to_use); 00041 00045 virtual ~CVwNativeCacheWriter(); 00046 00052 virtual void set_file(int32_t f); 00053 00059 virtual void cache_example(VwExample* &ex); 00060 00066 virtual const char* get_name() const { return "VwNativeCacheWriter"; } 00067 00068 private: 00072 void init(); 00073 00078 void write_header(); 00079 00088 char* run_len_encode(char *p, vw_size_t i); 00089 00097 inline uint32_t ZigZagEncode(int32_t n) 00098 { 00099 uint32_t ret = (n << 1) ^ (n >> 31); 00100 00101 return ret; 00102 } 00103 00112 char* bufcache_label(VwLabel* ld, char* c); 00113 00119 void cache_label(VwLabel* ld); 00120 00126 void cache_tag(v_array<char> tag); 00127 00133 void output_byte(unsigned char s); 00134 00142 void output_features(unsigned char index, VwFeature* begin, VwFeature* end); 00143 00144 protected: 00146 CIOBuffer buf; 00147 00148 private: 00150 vw_size_t neg_1; 00152 vw_size_t general; 00154 vw_size_t int_size; 00155 }; 00156 00157 } 00158 #endif // _VW_NATIVECACHE_WRITE_H__