http://www.allthingsdistributed.com/2007/10/amazons_dynamo.html
Overview of techniques used in building a scalabale decentralized key value store.
Overview of techniques used in building a scalabale decentralized key value store.
Sample program to work with CLI options. Play with this program options and pay attention to the reported usage errors to better understand how GetOptions() work. # CODE STARTS HERE
#!perl -w =head1 Using GetOptions() to process CLI options Ref: http://perldoc.perl.org/Getopt/Long.html =cut # Required module use Getopt::Long; use strict; my $grade = 'A'; my $pcile = 0.0; my $name = ''; my $result = 0; # Fail by default my $promote = 0; my @marks = (); my %history = (); sub show_usage() { print "\nUsage: --name name --grade [A|B|C|D] --marks m1 m2 m3\n" . " [--pass] [--promote | --nopromote]\n\n"; exit( 0 ); } if ( !scalar( @ARGV ) ) { show_usage(); } if ( !GetOptions( 'name=s' => \$name, # = - mandatory, string 'grade:s' => \$grade, # : - optional, string 'percentile:f' => \$pcile, # read float value 'marks=i{3}' => \@marks, # sequence of 3 numerals 'pass' => \$result, # optional, flag 'promote!' => \$promote, # -promote and -nopromote 'history:s{2}' => \%history ) ) # sequence of 2 strings { show_usage(); } print "\n SUMMARY \n\n"; print "Name : $name\n"; print "Marks : "; foreach( @marks ) { print $_ . " "; } print "\n"; print "Grade : $grade\n"; print "Percentile: $pcile\n"; print "Result : $result\n"; print "Promote? : $promote\n"; print "\n"; print "History : "; foreach( keys( %history ) ) { print $_ . " = " . $history{$_} . "; "; } print "\n"; 0; # CODE ENDS HERE
int process_data( const char * str, char delim = ' ' );Suddenly another component that depends on the modified header fails to compile with error C2143: missing ')' before 'string'. That's a bit of shock!. By the way the other component doesn't use the new API at all.
#define delim TEXT(" ") // andYou are punished for using a simple looking identifier (delim) and it takes efforts to understand that you are being punished!
#define TEXT( str ) L##str // just token pasting ...
#define INT32_MIN -2147483648
if ( 1 > INT32_MIN ) // comparing two unsigned values
std::cout << "I am sure, 1 gt INT32_MIN";
else
std::cout << "Surprse! it says, 1 lt INT32_MIN";
#define INT32_MIN (-2147483647 - 1) // don't forget to put the braces around
void PrintUsage()
{
std::cout << "#mycmd -option1 -subopt1 -subopt2 -suboption3 \n\
-option2 -subopt1 -sbuopt2 -subopt3 \n\
......................... \n\
......................... \n\
-option15 -subopt1 -subopt2"
<< std::endl;
}
void PrintUsage()
{
std::cout << "#mycmd -option1 -subopt1 -subopt2 -suboption3 \n\
-option2 -subopt1 -sbuopt2 -subopt3 \n\
......................... \n\
.........................\n\
-option9 -subopt1 -subopt2";
std::cout << " -option10 -subopt1 -subopt2 -suboption3 \n\
-option11 -subopt1 -sbuopt2 -subopt3 \n\
......................... \n\
.........................\n\
-option15 -subopt1 -subopt2";
<< std::endl;
}
With two un-named structures , the linker on Windows has thrown the following error
unnamed_struct.obj : fatal error LNK1179: invalid or corrupt file:
duplicate COMDAT '??1@@QAE@XZ'
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual
Studio 8\VC\BIN\link.EXE"' : return code '0x49b'
Stop.
The above is observed even with the varying number of struct members.
Known Issue: If two unnamed structs both declare a method with the same signature
and both are referenced, the compiler generates the same signature for both methods.
The linker then flags the .obj file as invalid due to duplicate COMDAT records
(More about this issue here)
The solution to this problem is, not to use more than one un-named structures
class RectangualShape {
public:
virtual void SetWidth( int w ) = 0;
virtual void SerHeight( int h ) = 0;
virtual int Area() = 0;
};
class Rectangle: public RectangularShape {
public:
virtual void SetWidth( int w ) { width = w; }
virtual void SetHeight( int h ) { height = h; }
virtual int Area() { return width * height; }
private:
int width;
int height;
};
class Square: public RectangularShape {
public:
virtual void SetWidth( int w ) { side = w; }
virtual void SetHeight( int h ) { side = h; }
virtual int Area() { return side* side; }
private:
int side;
};
int main()
{
int w= 1;
int h = 2;
RectangualShape *rect = new Rectangle();
rect->SetWidth( w );
rect->SetHeight( h );
assert( (w * h) == rect->Area() );
RectangualShape *sqr = new Square();
sqr->SetWidth( w );
sqr->SetHeight( h );
assert( (w * h) == sqr->Area() ); // BINGO, assertion fails
return 0;
}
class RectangualShape {
public:
/**
* Precond: Positive integer < 100
* Postcond: void
*/
// w should have been unsigned, precond should help us
virtual void SetWidth( int w ) = 0;
/**
* Precond: Positive integer < 100
* Postcond: void
*/
virtual void SerHeight( int h ) = 0;
/**
* Precond: void
* Postcond: w * h
*/
virtual int Area() = 0;
};