Dist m4ri 0.16.1
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
69static inline int one_ordered_ins(one_vec_t * const err, const int j){
70 int pos=err->wei-1;
71 while((pos >= 0) && (j < err->vec[pos])){
72 err->vec[pos+1] = err->vec[pos];
73 pos--;
74 }
75#ifndef NDEBUG
76 if ((pos >= 0) && (j == err->vec[pos]))
77 ERROR("Unexpected! vec[%d]=%d is already present!",pos,j);
78#endif
79 err->vec[pos+1]=j;
80#ifndef NDEBUG
81 for(int i=0; i < err->wei; i++)
82 if(err->vec[i] >= err->vec[i+1]){
83 printf("check ordering at i=%d! ",i);
84 one_vec_print(err);
85 ERROR("unexpected");
86 }
87#endif
88 err->wei ++;
89 return pos+1;
90}
91
95static inline int one_ordered_search(one_vec_t * const err, const int val){
97 int bot=0, top=err->wei , mid=0;
98#ifndef NDEBUG
99 if (!top)
100 return -1;
101#endif
102 while(top - bot > 1){
103 mid = (top+bot) >> 1;
104#ifndef NDEBUG
105 if (mid>=err->wei)
106 ERROR("this should not happen");
107#endif
108 if (err->vec[mid] <= val)
109 bot = mid;
110 else
111 top = mid;
112 }
113 if ( err->vec[bot] == val)
114 return bot;
115 else
116 return -1;
117}
118
120static inline void one_ordered_pos_del(
121 one_vec_t * const err, _maybe_unused const int val, const int pos
122) {
123#ifndef NDEBUG
124 if ((pos < 0) || (pos >= err->wei) || (err->wei == 0)
125 || (err->vec[pos] != val))
126 ERROR("this should not happen!");
127#endif
128 err->wei--;
129 for (int i = pos; i < err->wei; i++)
130 err->vec[i] = err->vec[i + 1];
131}
132
136static inline int one_ordered_find_del(one_vec_t * const err, const int val) {
137 int pos = one_ordered_search(err, val);
138 if (pos == -1)
139 return 0;
140 one_ordered_pos_del(err, val, pos);
141 return 1;
142}
143
144int start_CC_recurs(one_vec_t *err, one_vec_t *urr, one_vec_t * const syn[],
145 const int w_limit, const int max_col_wt,
146 const csr_t * const mH, const csr_t * const mHT,
147 params_t * const p);
148
149int do_CC_dist(params_t * const p);
150
151#ifdef __cplusplus
152}
153#endif
154
155#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:173
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:55
#define _maybe_unused
Definition mmio.c:17
int vec[0]
Definition util_hash.h:48
int * p
Definition util_m4ri.h:125
int * i
Definition util_m4ri.h:126
int rows
Definition util_m4ri.h:121
Utility functions for use with uthash.h.
struct ONE_VEC_T one_vec_t
params_t *const p
Definition util_io.c:93
#define ERROR(fmt,...)
Definition util_m4ri.h:13