j'ai mon code il me reste que deux erreur a corriger un aide s'il vou plai
le fichier source BloomFilter.c
voici le fichier BloomFilter.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include <iostream> #include <fstream> #include <iterator> #include <algorithm> #include <vector> #include "BloomFilter.h" using namespace std; void read_file(const std::string file_name, std::vector<std::string>& buffer) { std::ifstream in_file(file_name.c_str()); if (!in_file) { return; } std::istream_iterator< std::string > is(in_file); std::istream_iterator< std::string > eof; std::copy( is, eof, std::back_inserter(buffer)); } std::string reverse(std::string str) { char tempch; /* Reverse the string */ for(unsigned int i=0; i < (str.length()/2); i++) { tempch = str[i]; str[i] = str[str.length() - i - 1]; str[str.length() - i - 1] = tempch; } return str; } int main(int argc, char* argv[]) { string ch; std::vector<std::string> word_list; read_file("word-list.txt",word_list); bloom_filter filter(word_list.size() * 32); for(unsigned int i = 0; i < word_list.size(); i++) { filter.insert(word_list[i]); } for(unsigned int i = 0; i < word_list.size(); i++) { if (!filter.contains(word_list[i])) { std::cout << "ERROR: key not found!" << std::endl; } } for(unsigned int i = 0; i < word_list.size(); i++) { if (filter.contains(word_list[i] + reverse(word_list[i]))) { std::cout << "ERROR: key that does not exist found!" << std::endl; } } return 1; }
et l'autre fichier .h GeneralHashFunctions.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
76
77
78
79
80
81
82
83
84
85 #ifndef INCLUDE_BLOOM_FILTER_H #define INCLUDE_BLOOM_FILTER_H #include <iostream> #include <vector> #include "GeneralHashFunctions.h" const unsigned int char_size = 0x08; // 8 bits in 1 char(unsigned) const unsigned char bit_mask[8] = { 0x01, //00000001 0x02, //00000010 0x04, //00000100 0x08, //00001000 0x10, //00010000 0x20, //00100000 0x40, //01000000 0x80 //10000000 }; class bloom_filter { public: bloom_filter(unsigned int tbl_size) { table_size = tbl_size; hash_table = new unsigned char[table_size]; for(std::size_t i = 0; i < table_size; ++i) hash_table[i] = 0; register_default_hash_functions(); } ~bloom_filter() { delete[] hash_table; } void register_default_hash_functions() { hash_function1.push_back(RSHash ); hash_function1.push_back(JSHash ); hash_function1.push_back(PJWHash ); hash_function1.push_back(BKDRHash); hash_function1.push_back(SDBMHash); hash_function1.push_back(DJBHash ); hash_function1.push_back(DEKHash ); hash_function1.push_back(APHash ); } void insert(const std::string& key) { for(std::size_t i = 0; i < hash_function1.size(); i++) { unsigned int hash = (hash_function1)[i](key) % (table_size * char_size); hash_table[hash / char_size] |= bit_mask[hash % char_size]; } } bool contains(const std::string& key) { for(std::size_t i = 0; i < hash_function1.size(); i++) { unsigned int hash = (hash_function1)[i](key) % (table_size * char_size); unsigned int bit = hash % char_size; if ((hash_table[hash / char_size] & bit_mask[bit]) != bit_mask[bit]) { return false; } } return true; } private: std::vector<hash_function> hash_function1; unsigned char* hash_table; unsigned int table_size; }; #endif
voici les erreur qu'il m'affiche
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #ifndef INCLUDE_GENERALHASHFUNCTION_C_H #define INCLUDE_GENERALHASHFUNCTION_C_H #include <stdio.h> typedef unsigned int (*hash_function)(char*, unsigned int len); unsigned int RSHash (char* str, unsigned int len); unsigned int JSHash (char* str, unsigned int len); unsigned int PJWHash (char* str, unsigned int len); unsigned int ELFHash (char* str, unsigned int len); unsigned int BKDRHash(char* str, unsigned int len); unsigned int SDBMHash(char* str, unsigned int len); unsigned int DJBHash (char* str, unsigned int len); unsigned int DEKHash (char* str, unsigned int len); unsigned int BPHash (char* str, unsigned int len); unsigned int FNVHash (char* str, unsigned int len); unsigned int APHash (char* str, unsigned int len); #endif
[root@localhost BloomFilter_-_CPP1]# g++ -Wall -Werror BloomFilter.c -o anisss
In file included from BloomFilter.c:6:
BloomFilter.h: In member function ‘void bloom_filter::insert(const std::string&)’:
BloomFilter.h:77: error: cannot convert ‘const std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ to ‘char*’ in argument passing
BloomFilter.h: In member function ‘bool bloom_filter::contains(const std::string&)’:
BloomFilter.h:86: error: cannot convert ‘const std::basic_string<char, std::char_traits<char>, std::allocator<char> >’ to ‘char*’ in argument passing
Partager