commit fa4d569b330383fba7787821ac17ae923819afae
parent 712c960d3971e81c46c5270b2f6dc15190ea3b9c
Author: Dominik Schmidt <das1993@hotmail.com>
Date: Thu, 27 Aug 2015 00:20:27 +0200
Add CVec_Compressed
Diffstat:
puzzle.d | | | 28 | ++++++++++++++++++++++++++++ |
1 file changed, 28 insertions(+), 0 deletions(-)
diff --git a/puzzle.d b/puzzle.d
@@ -143,6 +143,10 @@ struct DVec{
struct CVec{
PuzzleCvec vec;
PuzzleContext *ctx;
+ this(ref CVec_Compressed c){
+ this(c.ctx);
+ puzzle_uncompress_cvec(ctx, &c.vec, &vec);
+ }
this(PuzzleContext *ctx){
this.ctx=ctx;
puzzle_init_cvec(ctx,&vec);
@@ -159,7 +163,31 @@ struct CVec{
double compare(in ref CVec b, bool hasText=false){
return puzzle_vector_normalized_distance(ctx,&vec,&b.vec,(hasText) ? 1 : 0);
}
+ CVec_Compressed compress(){
+ return CVec_Compressed(this);
+ }
@property size_t length(){
return vec.sizeof_vec;
}
}
+struct CVec_Compressed{
+ PuzzleCompressedCvec vec;
+ PuzzleContext *ctx;
+ this(ref CVec c){
+ this(c.ctx);
+ puzzle_compress_cvec(ctx, &vec, &c.vec);
+ }
+ this(PuzzleContext *ctx){
+ this.ctx=ctx;
+ puzzle_init_compressed_cvec(ctx,&vec);
+ }
+ ~this(){
+ puzzle_free_compressed_cvec(ctx,&vec);
+ }
+ CVec uncompress(){
+ return CVec(this);
+ }
+ @property size_t length(){
+ return vec.sizeof_compressed_vec;
+ }
+}