0% found this document useful (0 votes)
29 views

00 Liz Roy Doc

The document appears to be C++ code that defines a template class called "hold" to store key-value pairs from a file, where the key is of type T and the value is of type V. It includes functions to read keys and values from a file based on their positions, add them to a list, retrieve keys and values from the list, and write the collected key-value pairs to a new output file. The code takes input and output file names as command line arguments and processes the input file to extract and store the key-value pairs in a list before writing them to the output file.

Uploaded by

ssfofo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

00 Liz Roy Doc

The document appears to be C++ code that defines a template class called "hold" to store key-value pairs from a file, where the key is of type T and the value is of type V. It includes functions to read keys and values from a file based on their positions, add them to a list, retrieve keys and values from the list, and write the collected key-value pairs to a new output file. The code takes input and output file names as command line arguments and processes the input file to extract and store the key-value pairs in a list before writing them to the output file.

Uploaded by

ssfofo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 9

π π

2 2 2 2
sin ⋅cos sin 2−cos2
spread=∫ log 2 (2+ )∂ θ ∧∫ log 2 (2+ )∂ θ , θ =2⋅π⋅n⋅f n⋅T 0
0 1−sin 2⋅cos 2 0 1−sin 2⋅cos2
1+n⋅p 1+n⋅(1− p)
α⋅log 2 ( )⋅log 2( )
1− p p δ⋅log 2 (1+iterator(event))
p 1− p
, p= , n=ifstreaam: : pos type
1+ ξ⋅log 2 (1+iterator (event ))
1+ 16⋅β⋅(1+cos 2)⋅e 1− p ∨e p
#include <bits/stdc++.h>
#include <iostream>
#include <ios>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstddef>
#include <cstdarg>
#include <cstdbool>
#include <cstring>
#include <cmath>
#include <math.h>
#include <fstream>
#include <typeinfo>
#include <queue>
#include <list>
#include <algorithm>

#ifndef pi
#define pi 22/7
#endif

#ifndef Min
#define Min(x, y) ( x <= y ) ? x : y
#endif

#ifndef Max
#define Max(x, y) ( x >= y ) ? x : y
#endif

#ifndef eval
#define eval(p) ((p >= 0) && ( p <= 1)) ? 1 - p * ( 1 -p ) : 1
#endif

using namespace std;

using std::ifstream;

using std::ofstream;

using std::vector;

using std::pair;

using std::cout;

using std::string;

using std::queue;

using std::end;

using std::begin;

const float T0 = 1 / 4;
float f0 = 0.0000;

fstream fptr;

ifstream::pos_type iy = std::ios::end;

template<class T, class V> class hold{

friend bool operator==( T& ch, hold& obj){

return( ch == obj.key );
}

public:

hold() : ptr() { }

hold(T& x, V& y) : key( x ) { offset.push( y );}

hold<T, V>(ifstream::pos_type& ix, const hold<T, V>& obj) : pObj( obj)


{ SetOffset( ix ); }

hold<T, V>(ifstream::pos_type& ix) { SetKey( ix ); }

~hold() {

if(ptr) delete ptr; else { }

if(pObj) delete pObj; else { }


}

inline virtual bool operator==( T& ch ){

return( ch == key );
}

inline virtual bool RetCh( ifstream::pos_type& ix, char* ch){

fptr.seekg( ix, std::ios::beg);

fptr.read(ch, sizeof(T));

return( true );

inline virtual float SetFloat(ifstream::pos_type& ix){

long N = (long)iy;

long n = (long)ix;

int m = (int)key;

float a = log2( 1 + n / ( N + m * (N - n)));

return( a );
}

inline virtual void SetKey(ifstream::pos_type& ix){

char* ch = new char[sizeof(T)];

if( RetCh(ix, ch)){

if((typeid(T) == typeid(int)) || (typeid(T) ==


typeid(short))) key = atoi(ch);

else if((typeid(T) == typeid(double)) || (typeid(T) ==


typeid(long))) key = atol(ch);

else if(typeid(T) == typeid(float)) key = atof(ch);

else if(typeid(T) == typeid(char)) key = (char)(*ch);

///else if(typeid(T) == typeid(string)) key = (string)


(*ch);

else{

fputs("not possible to run away \n", stderr);

exit(EXIT_FAILURE);
}
}else{

fputs("not possible to run over away \n", stderr);

exit(EXIT_FAILURE);
}

delete[] ch;
}

inline virtual void SetOffset(ifstream::pos_type& ix){

if(typeid(V) == typeid(long)) offset.push((long)ix);

else if(typeid(V) == typeid(double)) offset.push((double)ix);

else if(typeid(V) == typeid(float)) offset.push(SetFloat( ix ));

else if(typeid(V) == typeid(int)) offset.push((int)ix);

else if(typeid(V) == typeid(ifstream::pos_type)) offset.push(ix);

else{

fputs(" not possible other type \n", stderr);

exit(EXIT_FAILURE);
}
}

inline virtual T GetKey() const { return( key ); }


inline virtual queue<V> GetOffset() const { return( offset ); }

inline virtual hold* GetPtr() const { return( ptr ); }

inline virtual hold<T, V>* GetpObj() const { return( pObj ); }

inline virtual void MakeClean() {

if( ptr ) delete ptr;

else if( pObj ) delete pObj;

else { }
}
private:

T key ;

queue<V> offset;

hold* ptr;

hold<T, V>* pObj;

};

template<class T, class V> void Ohold(ifstream::pos_type& ix, list<hold<T, V>>&


vct){

hold<T, V>* obj = new hold<T, V>(ix);

obj->SetOffset(ix);

vct.push_back(*obj);

delete obj;
}

template<class T, class V> void SetList(ifstream::pos_type& ix, list<hold<T, V>>&


vct){

if( vct.size() ){

bool ae = false;

hold<T, V> dx = hold<T, V>(ix);

for(auto& k : vct){

if(k.operator==(dx.key, k)){

k.SetOffset( ix );

if( ae == false ) ae = true;


}
}

if( ae == false ){
dx.SetOffset( ix );

vct.push_back( dx );

dx.MakeClean();
}

}else Ohold(ix, vct);


}

int main( int argc, char** argv ){

if( argc != 3 ){

fputs("not enough to run over away ( usage eval in out ) \n", stderr);

exit(EXIT_FAILURE);

}else{

std::list<hold<short, float>> vct;

fptr.open(argv[1], std::ios::in | std::ios::binary);

if(fptr && (fptr.good())){

}else{

fputs(" not possible to open input \n", stderr);

exit(EXIT_FAILURE);

}
fptr.close();

ofstream gptr( argv[2], std::ios::out | std::ios::binary );

for( auto& z : vct ){

gptr << z.GetKey();

queue<float> vl = z.GetOffset();

do{
gptr << vl.front();

vl.pop();

}while( !vl.empty());
}

gptr.close();

return 0;
}
}

You might also like