Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
rjzak committed Jul 15, 2020
1 parent 65d29d5 commit de88f89
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.o
*.so
*.a
21 changes: 19 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
INCLUDESRV=$(shell pg_config --includedir-server)
INCLUDEDIR=$(shell pg_config --includedir)
INSTALLDIR=$(shell pg_config --pkglibdir)

all: sdhash_psql.so
INCLUDES = -I sdhash/sdbf/
MISC = -Wall

all: main
all: main sdhash_psql.so

sdhash_psql.o: sdhash_psql.c sdhash_helper.h
gcc -I$(INCLUDESRV) -I$(INCLUDEDIR) -fPIC -c sdhash_psql.c ${MISC}

sdhash_psql.so: sdhash_psql.o sdhash_helper.o
gcc -fopenmp -shared -Wl,--no-as-needed -o sdhash_psql.so sdhash_psql.o sdhash_helper.o sdhash/libsdbf.a sdhash/external/stage/lib/libboost_thread.a sdhash/external/stage/lib/libboost_filesystem.a -lcrypto -lm -lc

install: sdhash_psql.so
install -g root -o root sdhash_psql.so $(INSTALLDIR)/sdhash_psql.so

sdhash_helper.o: sdhash_helper.h sdhash_helper.cpp
g++ -c sdhash_helper.cpp -fPIC ${INCLUDES} ${MISC}

main.o: main.cpp
g++ -c main.cpp ${INCLUDES} ${MISC}
Expand All @@ -11,4 +28,4 @@ main: main.o

.phony: clean
clean:
rm *.o main
rm *.o *.so main
20 changes: 20 additions & 0 deletions sdhash_psql.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "postgres.h"
#include "fmgr.h"
#include "sdhash_helper.h"

PG_MODULE_MAGIC;

#define MAX_SIZE 10000000

PG_FUNCTION_INFO_V1(pg_sdhash_compare);
Datum pg_sdhash_compare(PG_FUNCTION_ARGS);

Datum pg_sdhash_compare(PG_FUNCTION_ARGS) {
text *arg1 = PG_GETARG_TEXT_P(0);
text *arg2 = PG_GETARG_TEXT_P(1);
int32 score = sdhash_similarity((char *) VARDATA(arg1), (char *) VARDATA(arg2));
PG_RETURN_INT32(score);
}
//
// CREATE OR REPLACE FUNCTION fuzzy_compare(TEXT, TEXT) RETURNS INTEGER AS 'ssdeep_psql.so', 'pg_fuzzy_compare' LANGUAGE 'C';
//
1 change: 1 addition & 0 deletions sdhash_psql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE OR REPLACE FUNCTION sdhash_compare(TEXT, TEXT) RETURNS INTEGER AS 'sdhash_psql.so', 'pg_sdhash_compare' LANGUAGE 'c';

0 comments on commit de88f89

Please sign in to comment.