00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <stdlib.h>
00035 #include <iostream>
00036 #include "bm.h"
00037 #include "bmserial.h"
00038
00039 using namespace std;
00040
00041
00042
00043
00044
00045
00046 const unsigned MAX_VALUE = 1000000;
00047
00048
00049
00050
00051
00052 void fill_bvector(bm::bvector<>* bv)
00053 {
00054 for (unsigned i = 0; i < MAX_VALUE; ++i)
00055 {
00056 if (rand() % 2500)
00057 {
00058 bv->set_bit(i);
00059 }
00060 }
00061 }
00062
00063
00064 void print_statistics(const bm::bvector<>& bv)
00065 {
00066 bm::bvector<>::statistics st;
00067 bv.calc_stat(&st);
00068
00069 cout << "Bits count:" << bv.count() << endl;
00070 cout << "Bit blocks:" << st.bit_blocks << endl;
00071 cout << "GAP blocks:" << st.gap_blocks << endl;
00072 cout << "Memory used:"<< st.memory_used << endl;
00073 cout << "Max.serialize mem.:" << st.max_serialize_mem << endl << endl;;
00074 }
00075
00076
00077 unsigned char* serialize_bvector(bm::bvector<>& bv)
00078 {
00079
00080 bv.optimize();
00081
00082 bm::bvector<>::statistics st;
00083 bv.calc_stat(&st);
00084
00085 cout << "Bits count:" << bv.count() << endl;
00086 cout << "Bit blocks:" << st.bit_blocks << endl;
00087 cout << "GAP blocks:" << st.gap_blocks << endl;
00088 cout << "Memory used:"<< st.memory_used << endl;
00089 cout << "Max.serialize mem.:" << st.max_serialize_mem << endl;
00090
00091
00092
00093 unsigned char* buf = new unsigned char[st.max_serialize_mem];
00094
00095
00096
00097 unsigned len = bm::serialize(bv, buf);
00098
00099 cout << "Serialized size:" << len << endl << endl;
00100
00101 return buf;
00102 }
00103
00104
00105 int main(void)
00106 {
00107 bm::bvector<> bv1;
00108 bm::bvector<> bv2;
00109
00110 bv2.set_new_blocks_strat(bm::BM_GAP);
00111
00112 fill_bvector(&bv1);
00113 fill_bvector(&bv2);
00114
00115 unsigned char* buf1 = serialize_bvector(bv1);
00116 unsigned char* buf2 = serialize_bvector(bv2);
00117
00118
00119
00120
00121
00122
00123
00124
00125 bm::bvector<> bv3;
00126
00127
00128
00129
00130
00131 bm::deserialize(bv3, buf1);
00132 bm::deserialize(bv3, buf2);
00133
00134 print_statistics(bv3);
00135
00136
00137
00138 bv3.optimize();
00139
00140 print_statistics(bv3);
00141
00142 delete [] buf1;
00143 delete [] buf2;
00144
00145 return 0;
00146 }
00147