---
title: calculateByFile
description: "调用隐私求交非平衡PSI类算子，实现两方隐私非平衡求交功能，目前支持双方输入字符串类型的数据集，返回结果为双方的字符串数据交集或交集的下标。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengcctrustzone/tee/kcal/kunpeng_kcal_16_0094.html
sourcePath: /source/zh/kunpengcctrustzone/tee/kcal/kunpeng_kcal_16_0094.html
indexId: 3bd5625071df037af90b0d5e0af0c5f4f31bc0d95029b80c1f79ae04c5c7003064
---
# calculateByFile

调用隐私求交非平衡PSI类算子，实现两方隐私非平衡求交功能，目前支持双方输入字符串类型的数据集，返回结果为双方的字符串数据交集或交集的下标。
```
int calculateByFile (
DG_TeeCtx *dgTeeCtx,
DG_AlgorithmsType type,
DG_MpcFileInput *input,
DG_MpcFileOutput *output
)
```


#### 参数

| 参数名 | 描述 | 取值范围 | 输入/输出 |
| --- | --- | --- | --- |
| dgTeeCtx | KCAL上下文信息 | 为initTeeCtx成功初始化的结果 | 输入 |
| type | 算子枚举 DG\_AlgorithmsType | 目前仅支持PSI\_UB | 输入 |
| input | DG\_MpcFileInput | 不能输入为NULL | 输入 |
| output | 计算结果 类型为：DG\_MpcFileOutput | 不能输入为NULL | 输出 |


**表1 DG_MpcFileInput结构体**

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| filePath | char\* | 文件路径 |
| pathLen | uint32\_t | 路径长度 |
| dataSize | uint64\_t | 数据大小 |


**表2 DG_MpcFileOutput结构体**

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| filePath | char\* | 文件路径 |
| pathLen | uint32\_t | 路径长度 |
| dataSize | uint64\_t | 数据大小 |


#### 返回值

- 成功：返回0。
- 失败：返回错误码。


#### 错误码

| 错误码 | 错误码值 | 描述 | 特殊说明 |
| --- | --- | --- | --- |
| DG\_ERR\_MPC\_TEE\_INVALID\_PARAM | 4501 | 无效参数 | \- |
| DG\_ERR\_MPC\_TEE\_INVALID\_ALGORITHM\_TYPE | 4502 | 无效算法类型 | \- |
| DG\_ERR\_MALLOC\_FAIL | 51 | 内存分配失败 | \- |
| DG\_ERR\_MPC\_TEE\_DIV\_IS\_ZERO | 4512 | 除0异常 | \- |
| DG\_FAILURE | 1 | 算子执行失败 | 参数校验失败 分片失败 接收对方数据失败 |


#### 依赖

- dgTeeCtx依赖  initTeeCtx
的成功初始化。
- 依赖的头文件为"data_guard_mpc.h"。


#### 示例

使用调用DG_InitPsiOpts成功后的teeOpts来调用calculateByFile接口。


```
#include  "data_guard_mpc.h"
int PsiUb::Run(const std::string &inputFilePath, const std::string &outputFilePath, int &outputCount)
{
DG_MpcFileInput teeFileInput;
teeFileInput.filePath = const_cast<char *>(inputFilePath.c_str());
teeFileInput.pathLen = static_cast<uint32_t>(inputFilePath.length());
DG_MpcFileOutput teeFileOutput;
teeFileOutput.filePath = const_cast<char *>(outputFilePath.c_str());
teeFileOutput.pathLen = static_cast<uint32_t>(outputFilePath.length());
teeFileOutput.dataSize = 0;
int res = opts_->calculateByFile(dgTeeCtx_, PSI_UB, &teeFileInput, &teeFileOutput);
outputCount = static_cast<int>(teeFileOutput.dataSize);
return res;
}
```

运行结果: res结果为0且output不为null。
