-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnseq.c
89 lines (70 loc) · 1.94 KB
/
nseq.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/************************************************************************
* nseq - a storage efficient nucleotide sequence datatype for PostgreSQL
*
* Copyright (c) 2014,2015 by Ernst-G. Schmid
*
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "postgres.h"
#include "fmgr.h"
#include "utils/array.h"
#include "utils/lsyscache.h"
#include "catalog/pg_type.h"
#include "nseq.h"
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
PG_FUNCTION_INFO_V1 (nseq_length);
PG_FUNCTION_INFO_V1 (nseq_size);
PG_FUNCTION_INFO_V1 (nseq_transscribe);
PG_FUNCTION_INFO_V1 (nseq_histogram);
Datum nseq_length (PG_FUNCTION_ARGS);
/*
* Return uncompressed length of nseq.
*/
Datum
nseq_length (PG_FUNCTION_ARGS)
{
NSEQ *nseq = PG_GETARG_NSEQ_P (0);
PG_RETURN_INT32 (nseq->size);
}
/*
* Return compressed size of nseq.
*/
Datum nseq_size (PG_FUNCTION_ARGS);
Datum
nseq_size (PG_FUNCTION_ARGS)
{
NSEQ *nseq = PG_GETARG_NSEQ_P (0);
PG_RETURN_INT32 (nseq->compressed_size);
}
Datum nseq_transscribe (PG_FUNCTION_ARGS);
Datum
nseq_transscribe (PG_FUNCTION_ARGS)
{
NSEQ *nseq = PG_GETARG_NSEQ_P (0);
nseq->rna = !nseq->rna;
PG_RETURN_NSEQ_P (nseq);
}
Datum nseq_histogram (PG_FUNCTION_ARGS);
Datum
nseq_histogram (PG_FUNCTION_ARGS)
{
NSEQ *nseq = PG_GETARG_NSEQ_P (0);
ArrayType *result = NULL;
Datum *result_data = (Datum *)palloc(4 * sizeof(Datum));
int16 typlen;
bool typbyval;
char typalign;
int8 i;
get_typlenbyvalalign(INT4OID, &typlen, &typbyval, &typalign);
for(i=0; i<HISTSZ; i++)
{
result_data[i] = Int32GetDatum((int32)nseq->histogram[i]);
}
result = construct_array((void *)result_data, HISTSZ, INT4OID, typlen, typbyval, typalign);
PG_RETURN_ARRAYTYPE_P (result);
}