Skylark (Sketching Library)  0.1
/var/lib/jenkins/jobs/Skylark/workspace/sketch/hash_transform_data.hpp
Go to the documentation of this file.
00001 #ifndef SKYLARK_HASH_TRANSFORM_DATA_HPP
00002 #define SKYLARK_HASH_TRANSFORM_DATA_HPP
00003 
00004 #ifndef SKYLARK_SKETCH_HPP
00005 #error "Include top-level sketch.hpp instead of including individuals headers"
00006 #else
00007 #include "sketch_transform_data.hpp"
00008 #endif
00009 
00010 #include <vector>
00011 
00012 namespace skylark { namespace sketch {
00013 
00019 template <template <typename> class IdxDistributionType,
00020           template <typename> class ValueDistribution>
00021 struct hash_transform_data_t : public sketch_transform_data_t {
00022     typedef sketch_transform_data_t base_t;
00023 
00024     typedef IdxDistributionType<size_t> idx_distribution_type;
00025     typedef ValueDistribution<double> value_distribution_type;
00026 
00033     hash_transform_data_t (int N, int S, base::context_t& context)
00034         : base_t(N, S, context, "HashTransform") {
00035         context = build();
00036     }
00037 
00038     virtual
00039     boost::property_tree::ptree to_ptree() const {
00040         SKYLARK_THROW_EXCEPTION (
00041           base::sketch_exception()
00042               << base::error_msg(
00043                  "Do not yet support serialization of generic hash transform"));
00044 
00045         return boost::property_tree::ptree();
00046     }
00047 
00048 protected:
00049 
00050     hash_transform_data_t (int N, int S, const base::context_t& context,
00051         const std::string type)
00052         : base_t(N, S, context, type) {
00053 
00054     }
00055 
00056     base::context_t build() {
00057         base::context_t ctx = base_t::build();
00058 
00059         idx_distribution_type row_idx_distribution(0, _S - 1);
00060         value_distribution_type row_value_distribution;
00061 
00062         row_idx   = ctx.generate_random_samples_array(
00063                         _N, row_idx_distribution);
00064         row_value = ctx.generate_random_samples_array(
00065                         _N, row_value_distribution);
00066 
00067         return ctx;
00068     }
00069 
00070     std::vector<size_t> row_idx; 
00071     std::vector<double> row_value; 
00073     inline void finalPos(size_t &rowid, size_t &colid, columnwise_tag) const {
00074         rowid = row_idx[rowid];
00075     }
00076 
00077     inline void finalPos(size_t &rowid, size_t &colid, rowwise_tag) const {
00078         colid = row_idx[colid];
00079     }
00080 
00081     inline double getValue(size_t rowid, size_t colid, columnwise_tag) const {
00082         return row_value[rowid];
00083     }
00084 
00085     inline double getValue(size_t rowid, size_t colid, rowwise_tag) const {
00086         return row_value[colid];
00087     }
00088 
00089     inline void get_res_size(int &rows, int &cols, columnwise_tag) const {
00090         rows = _S;
00091     }
00092 
00093     inline void get_res_size(int &rows, int &cols, rowwise_tag) const {
00094         cols = _S;
00095     }
00096 };
00097 
00098 } } 
00100 #endif