SortUlongString.cpp

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 1999-2009 Soeren Sonnenburg
00008  * Written (W) 1999-2008 Gunnar Raetsch
00009  * Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00010  */
00011 
00012 #include "preproc/SortUlongString.h"
00013 #include "features/Features.h"
00014 #include "features/StringFeatures.h"
00015 #include "lib/Mathematics.h"
00016 
00017 using namespace shogun;
00018 
00019 CSortUlongString::CSortUlongString()
00020 : CStringPreProc<uint64_t>("SortUlongString", "STUS")
00021 {
00022 }
00023 
00024 CSortUlongString::~CSortUlongString()
00025 {
00026 }
00027 
00029 bool CSortUlongString::init(CFeatures* f)
00030 {
00031     ASSERT(f->get_feature_class()==C_STRING);
00032     ASSERT(f->get_feature_type()==F_ULONG);
00033 
00034     return true;
00035 }
00036 
00038 void CSortUlongString::cleanup()
00039 {
00040 }
00041 
00043 bool CSortUlongString::load(FILE* f)
00044 {
00045     SG_SET_LOCALE_C;
00046     SG_RESET_LOCALE;
00047     return false;
00048 }
00049 
00051 bool CSortUlongString::save(FILE* f)
00052 {
00053     SG_SET_LOCALE_C;
00054     SG_RESET_LOCALE;
00055     return false;
00056 }
00057 
00061 bool CSortUlongString::apply_to_string_features(CFeatures* f)
00062 {
00063     int32_t i;
00064     int32_t num_vec=((CStringFeatures<uint64_t>*)f)->get_num_vectors();
00065 
00066     for (i=0; i<num_vec; i++)
00067     {
00068         int32_t len=0;
00069         bool free_vec;
00070         uint64_t* vec=((CStringFeatures<uint64_t>*)f)->
00071             get_feature_vector(i, len, free_vec);
00072         ASSERT(!free_vec); // won't work with non-in-memory string features
00073 
00074         SG_DEBUG( "sorting string of length %i\n", len);
00075 
00076         //CMath::qsort(vec, len);
00077         CMath::radix_sort(vec, len);
00078     }
00079     return true;
00080 }
00081 
00083 uint64_t* CSortUlongString::apply_to_string(uint64_t* f, int32_t& len)
00084 {
00085     uint64_t* vec=new uint64_t[len];
00086     int32_t i=0;
00087 
00088     for (i=0; i<len; i++)
00089         vec[i]=f[i];
00090 
00091     //CMath::qsort(vec, len);
00092     CMath::radix_sort(vec, len);
00093 
00094     return vec;
00095 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation