File: compress_atomic_vector.c

package info (click to toggle)
r-bioc-delayedarray 0.32.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,596 kB
  • sloc: ansic: 79; makefile: 2
file content (89 lines) | stat: -rw-r--r-- 2,098 bytes parent folder | download | duplicates (2)
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
/****************************************************************************
 *              Compression/decompression of an atomic vector               *
 *                            Author: H. Pag\`es                            *
 ****************************************************************************/
#include "DelayedArray.h"


/* TODO: This stuff has nothing to do here! Get rid of it or move it to
   S4Vectors. */

/****************************************************************************
 * C_simple_object_size()
 */

#define FIXED_SIZE	48  /* object.size(raw(0)) or object.size(list()) */

/* Only supports naked atomic vectors, possibly wrapped in a naked list. */
static size_t simple_object_size(SEXP x)
{
	R_xlen_t x_len;
	size_t s;

	if (ATTRIB(x) != R_NilValue)
		error("attributes not supported by simple_object_size()");
	x_len = XLENGTH(x);
	s = (size_t) x_len;
	switch (TYPEOF(x)) {
	    case LGLSXP: case INTSXP:
		s *= sizeof(int);
	    break;
	    case REALSXP:
		s *= sizeof(double);
	    break;
	    case CPLXSXP:
		s *= sizeof(Rcomplex);
	    break;
	    case RAWSXP:
	    break;
	    case VECSXP:
		s *= sizeof(SEXP);
		for (R_xlen_t i = 0; i < x_len; i++)
			s += simple_object_size(VECTOR_ELT(x, i));
	    break;
	    default:
		error("object of type %s not supported "
		      "by simple_object_size()",
		      CHAR(type2str(TYPEOF(x))));
	}
	return s + FIXED_SIZE;
}

SEXP C_simple_object_size(SEXP x)
{
	size_t s;

	s = simple_object_size(x);
	return s <= INT_MAX ? ScalarInteger((int) s) : ScalarReal((double) s);
}


/****************************************************************************
 * C_encode_atomic_vector() / C_decode_atomic_vector()
 */

SEXP C_encode_atomic_vector(SEXP x)
{
	return R_NilValue;
}

SEXP C_decode_atomic_vector(SEXP x)
{
	return R_NilValue;
}


/****************************************************************************
 * C_compress_atomic_vector() / C_decompress_atomic_vector()
 */

SEXP C_compress_atomic_vector(SEXP x)
{
	return R_NilValue;
}

SEXP C_decompress_atomic_vector(SEXP x)
{
	return R_NilValue;
}