SHOGUN
v3.0.0
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
shogun
preprocessor
SortUlongString.cpp
Go to the documentation of this file.
1
/*
2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 3 of the License, or
5
* (at your option) any later version.
6
*
7
* Written (W) 1999-2009 Soeren Sonnenburg
8
* Written (W) 1999-2008 Gunnar Raetsch
9
* Copyright (C) 1999-2009 Fraunhofer Institute FIRST and Max-Planck-Society
10
*/
11
12
#include <
shogun/preprocessor/SortUlongString.h
>
13
#include <
shogun/features/Features.h
>
14
#include <
shogun/features/StringFeatures.h
>
15
#include <
shogun/mathematics/Math.h
>
16
17
using namespace
shogun;
18
19
CSortUlongString::CSortUlongString
()
20
:
CStringPreprocessor
<uint64_t>()
21
{
22
}
23
24
CSortUlongString::~CSortUlongString
()
25
{
26
}
27
29
bool
CSortUlongString::init(
CFeatures
* f)
30
{
31
ASSERT
(f->
get_feature_class
()==
C_STRING
)
32
ASSERT
(f->
get_feature_type
()==
F_ULONG
)
33
34
return
true
;
35
}
36
38
void
CSortUlongString::cleanup
()
39
{
40
}
41
43
bool
CSortUlongString::load
(FILE* f)
44
{
45
SG_SET_LOCALE_C
;
46
SG_RESET_LOCALE
;
47
return
false
;
48
}
49
51
bool
CSortUlongString::save
(FILE* f)
52
{
53
SG_SET_LOCALE_C
;
54
SG_RESET_LOCALE
;
55
return
false
;
56
}
57
61
bool
CSortUlongString::apply_to_string_features
(
CFeatures
* f)
62
{
63
int32_t i;
64
int32_t num_vec=((
CStringFeatures<uint64_t>
*)f)->get_num_vectors();
65
66
for
(i=0; i<num_vec; i++)
67
{
68
int32_t len=0;
69
bool
free_vec;
70
uint64_t* vec=((
CStringFeatures<uint64_t>
*)f)->
71
get_feature_vector(i, len, free_vec);
72
ASSERT
(!free_vec)
// won't work with non-in-memory string features
73
74
SG_DEBUG
(
"sorting string of length %i\n"
, len)
75
76
//CMath::qsort(vec, len);
77
CMath::radix_sort
(vec, len);
78
}
79
return
true
;
80
}
81
83
uint64_t*
CSortUlongString::apply_to_string
(uint64_t* f, int32_t& len)
84
{
85
uint64_t* vec=SG_MALLOC(uint64_t, len);
86
int32_t i=0;
87
88
for
(i=0; i<len; i++)
89
vec[i]=f[i];
90
91
//CMath::qsort(vec, len);
92
CMath::radix_sort
(vec, len);
93
94
return
vec;
95
}
SHOGUN
Machine Learning Toolbox - Documentation