Dist m4ri 0.0.1.alpha
Computing distance of a classical or quantum CSS code
Loading...
Searching...
No Matches
dist_cc.h
Go to the documentation of this file.
1#ifndef DIST_CC_H
2#define DIST_CC_H
3
4/************************************************************************
5 * @file dist_cc.h
6 * @brief Connected Cluster (CC) algorithm routines and helpers
7 *
8 * author: Leonid Pryadko <leonid.pryadko@ucr.edu>, Weilei Zeng
9 ************************************************************************/
10
11#include <inttypes.h>
12#include <strings.h>
13#include <stdlib.h>
14#include <stdio.h>
15#include <time.h>
16#include <m4ri/m4ri.h>
17
18#include "mmio.h"
19#include "uthash.h"
20#include "util_hash.h"
21#include "util_m4ri.h"
22#include "util_io.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
29static inline int one_csr_row_combine(one_vec_t * const v1, const one_vec_t * const v0,
30 const csr_t * const mat, const int row){
31#ifndef NDEBUG
32 if ((!v1) || (!v0) || (!mat))
33 ERROR("all arguments must be allocated: v1=%p v0=%p mat=%p\n",v1,v0,mat);
34 if(v1 == v0)
35 ERROR("the two vectors should not be the same !");
36 if((row<0) || (row >= mat->rows))
37 ERROR("this should not happen\n");
38#endif
39 int iM, i0=0, i1=0;
40 for (iM = mat->p[row]; iM < mat->p[row+1]; iM++){
41 const int ic = mat->i[iM];
42 while((i0 < v0->wei) && (v0->vec[i0] < ic))
43 v1->vec[i1++] = v0->vec[i0++];
44 if(i0 >= v0->wei)
45 break;
46 if(v0->vec[i0]==ic)
47 i0++;
48 else
49 v1->vec[i1++] = ic;
50 }
51 if(i0 >= v0->wei)
52 for ( ; iM < mat->p[row+1]; iM++){
53 const int ic = mat->i[iM];
54 v1->vec[i1++] = ic;
55 }
56 else
57 while(i0 < v0->wei)
58 v1->vec[i1++] = v0->vec[i0++];
59
60 v1->wei = i1;
61 return i1;
62}
63
65static inline int one_ordered_ins(one_vec_t * const err, const int j){
66 int pos=err->wei-1;
67 while(j < err->vec[pos]){
68 err->vec[pos+1] = err->vec[pos];
69 pos--;
70 }
71#ifndef NDEBUG
72 if (j == err->vec[pos])
73 ERROR("Unexpected! vec[%d]=%d is already present!",pos,j);
74#endif
75 err->vec[pos+1]=j;
76#ifndef NDEBUG
77 for(int i=0; i < err->wei; i++)
78 if(err->vec[i] >= err->vec[i+1]){
79 printf("check ordering at i=%d! ",i);
80 one_vec_print(err);
81 ERROR("unexpected");
82 }
83#endif
84 err->wei ++;
85 return pos+1;
86}
87
91static inline int one_ordered_search(one_vec_t * const err, const int val){
93 int bot=0, top=err->wei , mid=0;
94#ifndef NDEBUG
95 if (!top)
96 return -1;
97#endif
98 while(top - bot > 1){
99 mid = (top+bot) >> 1;
100#ifndef NDEBUG
101 if (mid>=err->wei)
102 ERROR("this should not happen");
103#endif
104 if (err->vec[mid] <= val)
105 bot = mid;
106 else
107 top = mid;
108 }
109 if ( err->vec[bot] == val)
110 return bot;
111 else
112 return -1;
113}
114
116static inline void one_ordered_pos_del(
117 one_vec_t * const err, _maybe_unused const int val, const int pos
118) {
119#ifndef NDEBUG
120 if ((pos < 0) || (pos >= err->wei) || (err->wei == 0)
121 || (err->vec[pos] != val))
122 ERROR("this should not happen!");
123#endif
124 err->wei--;
125 for (int i = pos; i < err->wei; i++)
126 err->vec[i] = err->vec[i + 1];
127}
128
132static inline int one_ordered_find_del(one_vec_t * const err, const int val) {
133 int pos = one_ordered_search(err, val);
134 if (pos == -1)
135 return 0;
136 one_ordered_pos_del(err, val, pos);
137 return 1;
138}
139
140int start_CC_recurs(one_vec_t *err, one_vec_t *urr, one_vec_t * const syn[],
141 const int w_limit, const int max_col_wt,
142 const csr_t * const mH, const csr_t * const mHT,
143 params_t * const p);
144
145int do_CC_dist(params_t * const p);
146
147#ifdef __cplusplus
148}
149#endif
150
151#endif /* DIST_CC_H */
void one_vec_print(const one_vec_t *const pvec)
distance of a classical or quantum CSS code
Definition dist_cc.c:32
int do_CC_dist(params_t *const p)
Definition dist_cc.c:159
int start_CC_recurs(one_vec_t *err, one_vec_t *urr, one_vec_t *const syn[], const int w_limit, const int max_col_wt, const csr_t *const mH, const csr_t *const mHT, params_t *const p)
recursively construct codewords
Definition dist_cc.c:54
#define _maybe_unused
Definition mmio.c:17
int vec[0]
Definition util_hash.h:46
int * p
Definition util_m4ri.h:115
int * i
Definition util_m4ri.h:116
int rows
Definition util_m4ri.h:111
Utility functions for use with uthash.h
params_t *const p
Definition util_io.c:52
#define ERROR(fmt,...)
Definition util_m4ri.h:13