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     return false;
00046 }
00047 
00049 bool CSortUlongString::save(FILE* f)
00050 {
00051     return false;
00052 }
00053 
00057 bool CSortUlongString::apply_to_string_features(CFeatures* f)
00058 {
00059     int32_t i;
00060     int32_t num_vec=((CStringFeatures<uint64_t>*)f)->get_num_vectors();
00061 
00062     for (i=0; i<num_vec; i++)
00063     {
00064         int32_t len=0;
00065         bool free_vec;
00066         uint64_t* vec=((CStringFeatures<uint64_t>*)f)->
00067             get_feature_vector(i, len, free_vec);
00068         ASSERT(!free_vec); // won't work with non-in-memory string features
00069 
00070         SG_DEBUG( "sorting string of length %i\n", len);
00071 
00072         //CMath::qsort(vec, len);
00073         CMath::radix_sort(vec, len);
00074     }
00075     return true;
00076 }
00077 
00079 uint64_t* CSortUlongString::apply_to_string(uint64_t* f, int32_t& len)
00080 {
00081     uint64_t* vec=new uint64_t[len];
00082     int32_t i=0;
00083 
00084     for (i=0; i<len; i++)
00085         vec[i]=f[i];
00086 
00087     //CMath::qsort(vec, len);
00088     CMath::radix_sort(vec, len);
00089 
00090     return vec;
00091 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation