-
Notifications
You must be signed in to change notification settings - Fork 0
/
func.h
76 lines (74 loc) · 2.33 KB
/
func.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef _FUNC_H
#define _FUNC_H
#include <stdio.h>
#include <iostream>
#include <string>
#include "string.h"
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <vector>
#include <sstream>
#include <map>
#define SHORT_LENTH 250
#define MAX_LENTH 50000
typedef struct{ std::string word; float d;}wdlen;
typedef std::vector<uint16_t> intvector;
namespace commom{
//日志类
void LOG_INFO(std::string str);
void DEBUG_INFO(std::string str);
class Func{
public://字符串处理
std::string GetLine( char* buffer );
std::string Unit(const std::string& str);
void Split(const char* d,const std::string& str, std::vector< std::string >& vec);
void Split(const char* d,const std::string& str, std::map<std::string, int>& vec);
void _Split(const char* d,const std::string& str, std::vector< std::string >& vec);
void SplitOnce(const char* d,const std::string& str, std::vector< std::string >& vec);
inline uint16_t Combine(char high, char low){ return (((uint16_t(high) & 0x00ff ) << 8) | (uint16_t(low) & 0x00ff)); }
bool StrToVec(const std::string& str, intvector& v);
uint16_t StrToInt(const std::string& str);
std::string VecToStr(intvector& v, int i,int j );
public://文件处理
char* ReadLine( char* buffer, int size, FILE *fi );
int WiteLine( const char *str, FILE *fo );
public://常用模版
template <class T> int MaxArray(T* prob, int n){
if((n < 1 )||(prob == NULL))return -1;
T temp = prob[0]; int index =0;
for(int i =0; i< n; i++){
if(temp < prob[i] ){
temp = prob[i]; index = i;
}
}
return index;
}
template <class T> int MinArray(T* prob, int n){
if((n < 1 )||(prob == NULL))return -1;
T temp = prob[0]; int index =0;
for(int i =0; i< n; i++){
if(temp > prob[i] ){
temp = prob[i]; index = i;
}
}
return index;
}
template <class T> std::string ConvertToStr(T value) {
std::stringstream ss; ss << value; return ss.str();
}
static bool SortByDistance(const wdlen& x, const wdlen& y){
return x.d > y.d;
}
static bool SortBySecondGreater(const std::pair<std::string, float>& x,
const std::pair<std::string, float>& y ){
return x.second > y.second;
}
static bool SortBySecondLess(const std::pair<std::string, float>& x,
const std::pair<std::string, float>& y ){
return x.second < y.second;
}
};
}
#endif