当前位置: 首页 > news >正文

使用纯C语言定义通用型数据结构的方法和示例

文章目录

  • 前言
  • 以实现优先队列来描述实现思想
  • 基本类型的包装类型
  • 比较函数
  • 演示
  • 总结

前言

最近一段时间在复习数据结构和算法,用的C语言,不得不说,不学个高级语言再回头看C语言根本不知道C语言的强大和完美,不过相比之下也有许多不便利的地方,尤其是以下两个方面:

  • 没有异常处理机制
  • 没有泛型

其中第一方面之前就解决了,详情请看在C语言中实现类似面向对象语言的异常处理机制,今天下午有空来实现一下泛型。不得不说,通过异常处理机制和泛型的实现,既让我C语言使用的得心应手,又让我对高级语言的设计有了亲身般体验。

以实现优先队列来描述实现思想

首先C语言本身不支持泛型,这意味着实现泛型有以下两个困难(解决这两个困难也就意味着成功):

  • ①:类型信息在编译前就已经确定了
  • ②:类型信息不能像参数一样传递

有了目标就轻松多了,于是我立刻就想到了函数的可变参数<stdarg.h>,请看下面的DEMO:

PackagingTypeList intBatchValueOf(int size, ...) {PackagingTypeList list = calloc(size, sizeof(PackagingType *));va_list argList;va_start(argList, size);for (int i = 0; i < size; ++i) {union PackagingType *pack = malloc(sizeof(PackagingType));pack->intValue = va_arg(argList, int);*(list + i) = pack;}va_end(argList);return list;
}

在使用va_arg取可变参数时我们确实直接将int类型作为参数传递了,这就意味着困难②克服了,那么困难①呢?于是我继续研究,我发现函数的参数存储在一个GCC内置的数据结构中:

typedef struct {void *__stack;					/* __stack 记录下一个匿名栈参数的存储位置, 随着va_arg的调用可能变化 */void *__gr_top;					/* __gr_top 记录最后一个匿名通用寄存器参数的尾地址, 其不随va_arg调用变化 */void *__vr_top;					/* __vr_top 记录最后一个匿名浮点寄存器参数的尾地址, 其不随va_arg调用变化 */int   __gr_offs;				    /* __gr_offs 记录下一个匿名通用寄存器参数到__gr_top的偏移(负数),随着va_arg的调用可能变化 */int   __vr_offs;					/* __vr_offs 记录下一个匿名浮点寄存器参数到__vr_top的偏移(负数),随着va_arg的调用可能变化 */
} __builtin_va_list;

这就意味着要想克服困难①就必须得到编译器的支持,显然这是不可能的,于是我果断放弃了,但困难②的克服给我了灵感,va_arg是一个宏定义,强大的预处理器赋予了C语言元编程的能力,这就是我想到的第一种方法:

  • 克服困难①:使用宏定义在编译时定义可以存储指定类型的优先队列,
  • 克服困难②:使用带参数的宏传递类型信息

于是第一种方案诞生了:

#define PriorityQueueNode(TYPE)                                                     \
{                                                                                   \typedef struct PriorityQueueNode_##TYPE{                                        \TYPE data;                                                                  \struct PriorityQueueNode *next;                                             \struct PriorityQueueNode *prior;                                            \}PriorityQueueNode_##TYPE;                                                      \
}while(false)#define priorityQueueEnQueue(TYPE)                                                  \
{                                                                                   \void priorityQueueEnQueue_##TYPE(struct PriorityQueue_##TYPE queue,TYPE data){  \...                                                                       \}                                                                               \
}while(false)#define PriorityQueue(TYPE, NAME)                                                   \
{                                                                                   \PriorityQueueNode(TYPE);                                                        \priorityQueueEnQueue(TYPE)                                                      \PriorityQueueNode_##TYPE head={.next=NULL,.prior=NULL};                         \struct PriorityQueue_##TYPE{                                                    \PriorityQueueNode *front;                                                   \PriorityQueueNode *rear;                                                    \void (* priorityQueueEnQueue)(struct PriorityQueue_##TYPE,TYPE);            \} NAME={                                                                        \.front=&head,                                                                \.rear=&head                                                                  \.priorityQueueEnQueue=priorityQueueEnQueue_##TYPE                            \};                                                                              \
}while(false)

不过还没等写完我就放弃了,因为这太不优雅了,这其实和单独为每种类型定义一个优先队列没什么区别,于是我又想到了void*指针,这就是我想到的第二个方法,也是最终实现的方法:

  • 克服困难①:使用void*指针存储任意数据类型的指针,实际存储数据的空间由调用者分配
  • 克服困难②:在数据结构内部需要类型信息的地方通过传入的函数完成,这个函数也由调用者提供
//PriorityQueue.h#ifndef INC_2023_PRIORITYQUEUE_H
#define INC_2023_PRIORITYQUEUE_H#include "../../../util/Util.h"typedef struct PriorityQueueNode PriorityQueueNode;
typedef struct PriorityQueue *PriorityQueue;/*** 构造带头结点的优先队列* @param compare* @return*/
PriorityQueue priorityQueueConstructor(int (*compare)(void *, void *)) throws NULL_POINTER_EXCEPTION;/*** 销毁优先队列* @param queue*/
void priorityQueueFinalize(PriorityQueue queue) throws NULL_POINTER_EXCEPTION;/*** 优先队列是否为空* @param queue* @return*/
bool priorityQueueIsEmpty(PriorityQueue queue) throws NULL_POINTER_EXCEPTION;/*** 入队* @param queue* @param element*/
void priorityQueueEnQueue(PriorityQueue queue, void *element) throws NULL_POINTER_EXCEPTION;/*** 出队* @param queue* @return*/
void *priorityQueueDeQueue(PriorityQueue queue) throws NULL_POINTER_EXCEPTION;#endif //INC_2023_PRIORITYQUEUE_H
//PriorityQueue.c#include "PriorityQueue.h"struct PriorityQueueNode {void *data;PriorityQueueNode *next;PriorityQueueNode *prior;
};struct PriorityQueue {PriorityQueueNode *front;PriorityQueueNode *rear;int (*compare)(void *, void *);
};/*** 构造带头结点的优先队列* @param compare* @return*/
PriorityQueue priorityQueueConstructor(int (*compare)(void *, void *)) throws NULL_POINTER_EXCEPTION {if (compare == NULL) {throw Error(NULL_POINTER_EXCEPTION, "比较函数不能为空");}PriorityQueue queue = malloc(sizeof(struct PriorityQueue));//头结点queue->front = queue->rear = malloc(sizeof(PriorityQueueNode));queue->front->next = NULL;queue->front->prior = NULL;queue->compare = compare;return queue;
}/*** 销毁优先队列* @param queue*/
void priorityQueueFinalize(PriorityQueue queue) throws NULL_POINTER_EXCEPTION {if (queue == NULL) {throw Error(NULL_POINTER_EXCEPTION, "优先队列不能为空");}for (; !priorityQueueIsEmpty(queue);) {priorityQueueDeQueue(queue);}free(queue->front);free(queue);
}/*** 优先队列是否为空* @param queue* @return*/
bool priorityQueueIsEmpty(PriorityQueue queue) throws NULL_POINTER_EXCEPTION {if (queue == NULL) {throw Error(NULL_POINTER_EXCEPTION, "优先队列不能为空");}if (queue->front == queue->rear) {return true;} else {return false;}
}/*** 入队* @param queue* @param element*/
void priorityQueueEnQueue(PriorityQueue queue, void *element) throws NULL_POINTER_EXCEPTION {if (queue == NULL) {throw Error(NULL_POINTER_EXCEPTION, "优先队列不能为空");}PriorityQueueNode *node = malloc(sizeof(PriorityQueueNode));node->data = element;//如果新加入元素优先级比队尾元素优先级小则直接插入队尾,否则就遍历优先队列找到合适的插入位置if (priorityQueueIsEmpty(queue) || queue->compare(queue->rear->data, node->data) > 0) {node->next = NULL;node->prior = queue->rear;queue->rear->next = node;queue->rear = node;} else {for (PriorityQueueNode *temp = queue->front->next; temp != NULL; temp = temp->next) {if (queue->compare(temp->data, node->data) <= 0) {node->next = temp;node->prior = temp->prior;temp->prior->next = node;temp->prior = node;break;}}}
}/*** 出队* @param queue* @return*/
void *priorityQueueDeQueue(PriorityQueue queue) throws NULL_POINTER_EXCEPTION {if (queue == NULL) {throw Error(NULL_POINTER_EXCEPTION, "优先队列不能为空");}if (!priorityQueueIsEmpty(queue)) {PriorityQueueNode *node = queue->front->next;void *data = node->data;if (queue->rear == node) {queue->rear = queue->front;queue->front->next = NULL;} else {queue->front->next = node->next;node->next->prior = queue->front;}free(node);return data;} else {return NULL;}
}

基本类型的包装类型

为了方便基本类型指针的获取,我定义了基本类型的包装类型:

//PackagingType.h#ifndef DSA_PACKAGINGTYPE_H
#define DSA_PACKAGINGTYPE_H#include <stdbool.h>
#include <stdarg.h>
#include <stdlib.h>typedef union PackagingType PackagingType, **PackagingTypeList;int getIntValue(void *element);float getFloatValue(void *element);double getDoubleValue(void *element);char getCharValue(void *element);bool getBoolValue(void *element);PackagingType *intValueOf(int value);PackagingTypeList intBatchValueOf(int size, ...);PackagingType *floatValueOf(float value);PackagingTypeList floatBatchValueOf(int size, ...);PackagingType *doubleValueOf(double value);PackagingTypeList doubleBatchValueOf(int size, ...);PackagingType *charValueOf(char value);PackagingTypeList charBatchValueOf(int size, ...);PackagingType *boolValueOf(bool value);PackagingTypeList boolBatchValueOf(int size, ...);#endif //DSA_PACKAGINGTYPE_H
//PackagingType.cunion PackagingType {int intValue;float floatValue;double doubleValue;char charValue;bool boolValue;
};int getIntValue(void *element) {return ((PackagingType *) element)->intValue;
}float getFloatValue(void *element) {return ((PackagingType *) element)->floatValue;
}double getDoubleValue(void *element) {return ((PackagingType *) element)->doubleValue;
}char getCharValue(void *element) {return ((PackagingType *) element)->charValue;
}bool getBoolValue(void *element) {return ((PackagingType *) element)->boolValue;
}PackagingType *intValueOf(int value) {union PackagingType *pack = malloc(sizeof(PackagingType));pack->intValue = value;return pack;
}PackagingTypeList intBatchValueOf(int size, ...) {PackagingTypeList list = calloc(size, sizeof(PackagingType *));va_list argList;va_start(argList, size);for (int i = 0; i < size; ++i) {union PackagingType *pack = malloc(sizeof(PackagingType));pack->intValue = va_arg(argList, int);*(list + i) = pack;}va_end(argList);return list;
}PackagingType *floatValueOf(float value) {union PackagingType *pack = malloc(sizeof(PackagingType));pack->floatValue = value;return pack;
}PackagingTypeList floatBatchValueOf(int size, ...) {PackagingTypeList list = calloc(size, sizeof(PackagingType *));va_list argList;va_start(argList, size);for (int i = 0; i < size; ++i) {union PackagingType *pack = malloc(sizeof(PackagingType));pack->intValue = va_arg(argList, double);*(list + i) = pack;}va_end(argList);return list;
}PackagingType *doubleValueOf(double value) {union PackagingType *pack = malloc(sizeof(PackagingType));pack->doubleValue = value;return pack;
}PackagingTypeList doubleBatchValueOf(int size, ...) {PackagingTypeList list = calloc(size, sizeof(PackagingType *));va_list argList;va_start(argList, size);for (int i = 0; i < size; ++i) {union PackagingType *pack = malloc(sizeof(PackagingType));pack->intValue = va_arg(argList, double);*(list + i) = pack;}va_end(argList);return list;
}PackagingType *charValueOf(char value) {union PackagingType *pack = malloc(sizeof(PackagingType));pack->charValue = value;return pack;
}PackagingTypeList charBatchValueOf(int size, ...) {PackagingTypeList list = calloc(size, sizeof(PackagingType *));va_list argList;va_start(argList, size);for (int i = 0; i < size; ++i) {union PackagingType *pack = malloc(sizeof(PackagingType));pack->intValue = va_arg(argList, int);*(list + i) = pack;}va_end(argList);return list;
}PackagingType *boolValueOf(bool value) {union PackagingType *pack = malloc(sizeof(PackagingType));pack->boolValue = value;return pack;
}PackagingTypeList boolBatchValueOf(int size, ...) {PackagingTypeList list = calloc(size, sizeof(PackagingType *));va_list argList;va_start(argList, size);for (int i = 0; i < size; ++i) {union PackagingType *pack = malloc(sizeof(PackagingType));pack->intValue = va_arg(argList, int);*(list + i) = pack;}va_end(argList);return list;
}

比较函数

通过创建多个数据结构发现,在数据结构内部用到的往往是比较函数,因此,我把常用的比较函数都定义了一下:

//Comparable.h#ifndef DSA_COMPARABLE_H
#define DSA_COMPARABLE_H#include "../packaging-type/PackagingType.h"extern int (*intCompare)(void *, void *);extern int (*intPackCompare)(void *, void *);extern int (*floatCompare)(void *, void *);extern int (*floatPackCompare)(void *, void *);extern int (*doubleCompare)(void *, void *);extern int (*doublePackCompare)(void *, void *);extern int (*charCompare)(void *, void *);extern int (*charPackCompare)(void *, void *);#endif //DSA_COMPARABLE_H
//Comparable.c#include "Comparable.h"int intComp(void *a, void *b) {return *((int *) a) - *((int *) b) > 0;
}int intPackComp(void *a, void *b) {return getIntValue(a) - getIntValue(b) > 0;
}int floatComp(void *a, void *b) {return *((float *) a) - *((float *) b) > 0;
}int floatPackComp(void *a, void *b) {return getFloatValue(a) - getFloatValue(b) > 0;
}int doubleComp(void *a, void *b) {return *((double *) a) - *((double *) b) > 0;
}int doublePackComp(void *a, void *b) {return getDoubleValue(a) - getDoubleValue(b) > 0;
}int charComp(void *a, void *b) {return *((char *) a) - *((char *) b) > 0;
}int charPackComp(void *a, void *b) {return getCharValue(a) - getCharValue(b) > 0;
}int (*intCompare)(void *, void *) =intComp;int (*intPackCompare)(void *, void *) =intPackComp;int (*floatCompare)(void *, void *) =floatComp;int (*floatPackCompare)(void *, void *) =floatPackComp;int (*doubleCompare)(void *, void *) =doubleComp;int (*doublePackCompare)(void *, void *) =doublePackComp;int (*charCompare)(void *, void *) =charComp;int (*charPackCompare)(void *, void *) =charPackComp;

演示

首先看一个基本类型的例子:

#include "util/Util.h"
#include "linear-structure/queue/priority-queue/PriorityQueue.h"int main() {PackagingTypeList list = intBatchValueOf(4, 1, 2, 3, 4);PriorityQueue queue = priorityQueueConstructor(intPackCompare);for (int i = 0; i < 4; ++i) {priorityQueueEnQueue(queue, *(list + i));}while (!priorityQueueIsEmpty(queue)) {printf("%d", getIntValue(priorityQueueDeQueue(queue)));}return 0;
}

在这里插入图片描述

再看一个结构类型的例子:

#include "util/Util.h"
#include "linear-structure/queue/priority-queue/PriorityQueue.h"struct Student {int age;char *name;
};int studentCompare(void *a, void *b) {return ((struct Student *) a)->age - ((struct Student *) b)->age > 0;
}int main() {struct Student a = {.age=18, .name="张三"}, b = {.age=28, .name="李四"};PriorityQueue queue = priorityQueueConstructor(studentCompare);priorityQueueEnQueue(queue, &a);priorityQueueEnQueue(queue, &b);while (!priorityQueueIsEmpty(queue)) {printf("%s,", ((struct Student *) priorityQueueDeQueue(queue))->name);}return 0;
}

在这里插入图片描述

最后看一个抛异常的例子:

#include "util/Util.h"
#include "linear-structure/queue/priority-queue/PriorityQueue.h"struct Student {int age;char *name;
};int studentCompare(void *a, void *b) {return ((struct Student *) a)->age - ((struct Student *) b)->age > 0;
}int main() {struct Student a = {.age=18, .name="张三"}, b = {.age=28, .name="李四"};PriorityQueue queue = priorityQueueConstructor(studentCompare);priorityQueueEnQueue(queue, &a);priorityQueueEnQueue(queue, &b);try {while (!priorityQueueIsEmpty(queue)) {printf("%s,", ((struct Student *) priorityQueueDeQueue(NULL))->name);//change to NULL}} catch(NULL_POINTER_EXCEPTION) {stdErr();}return 0;
}

在这里插入图片描述

总结

  • 第一种方法类似于C++的方式
  • 第二种方法类似于Java的方式

相关文章:

使用纯C语言定义通用型数据结构的方法和示例

文章目录 前言以实现优先队列来描述实现思想基本类型的包装类型比较函数演示总结 前言 最近一段时间在复习数据结构和算法&#xff0c;用的C语言&#xff0c;不得不说&#xff0c;不学个高级语言再回头看C语言根本不知道C语言的强大和完美&#xff0c;不过相比之下也有许多不便…...

数据结构基础8:二叉树oj+层序遍历。

二叉树oj层序遍历 题目一&#xff1a;二叉树的销毁&#xff1a;方法一&#xff1a;前序遍历&#xff1a;方法二&#xff1a;后序遍历&#xff1a; 题目二&#xff1a;二叉树查找值为x的节点方法一&#xff1a;方法二&#xff1a;方法三&#xff1a; 题目三&#xff1a;层序遍历…...

Spring注解家族介绍:@RestController

前言&#xff1a; Spring Boot可以说是当前JAVA最为重要的一个框架&#xff0c;而Spring Boot的基石Spring中有着丰富的注解&#xff0c;因此我们会利用几篇文章来讲解我目前学到的各种注解&#xff0c;因此本类型文章的篇幅会比较短&#xff0c;主要着重于介绍各个注解。 目录…...

rocketmq

&#x1f353;代码仓库 https://gitee.com/xuhx615/rocket-mqdemo.git &#x1f353;基本概念 ⭐生产者(Producer)&#xff1a;消息发布者⭐主题&#xff08;Topic&#xff09;&#xff1a;topic用于标识同一类业务类型的消息⭐消息队列&#xff08;MessageQueue&#xff09…...

JAVA成员变量首字母小写,第二个字母大写报错问题(原因:Lombok与Spring冲突)

1、问题现象&#xff1a; JAVA类里定义成员变量使用首字母小写&#xff0c;第二个字母大写 Getter Setter public class BrandQueryObject extends QueryObject{private String pName; }结果页面报错&#xff0c;无法找到类型为 cn.wolfcode.ssm.query.BrandQueryObject 的对象…...

Python入门教程 |Python 错误和异常

Python3 错误和异常 作为 Python 初学者&#xff0c;在刚学习 Python 编程时&#xff0c;经常会看到一些报错信息&#xff0c;在前面我们没有提及&#xff0c;这章节我们会专门介绍。 Python 有两种错误很容易辨认&#xff1a;语法错误和异常。 Python assert&#xff08;断…...

API商品接口对接使用:从理论到实践

随着电子商务的飞速发展&#xff0c;API商品接口已成为现代电子商务应用程序不可或缺的一部分。通过API商品接口&#xff0c;开发者可以轻松地从其他应用程序或服务中获取商品信息&#xff0c;实现快速、高效的电子商务功能。本文将探讨API商品接口的概念、对接使用的方法以及一…...

解决stable diffusion webui1.6 wd1.4 tagger加载失败的问题

由于webui源码的变化&#xff0c;需要修改两个地方的import 1.tagger/ui.py # 第十行 # from webui import wrap_gradio_gpu_call # 原代码 from modules.call_queue import wrap_gradio_gpu_call1.preload.py # 第4行开始 # from modules.shared import models_path # 原…...

Python学习-实现简单的http服务

基于Python实现一个简单的HttpServer,当用户在浏览器中输入IP地址:8000时&#xff0c;则会返回index.html页面内容&#xff0c;访问其它信息&#xff0c;则会返回错误信息(404) """ httpserver v1.0 1.获取来自浏览器的请求&#xff0c; 2.判断如果请求内容是 …...

#循循渐进学51单片机#变量进阶与点阵LED#not.6

1、掌握变量的作用域及存储类别。 局部变量 函数内部声明的变量&#xff0c;只在函数内部有效&#xff0c;在本函数以外是不能使用的&#xff0c;叫局部变量。 全局变量 在函数外部声明的变量就是全局变量&#xff0c;一个源程序可以包含一个或多个函数&#xff0c;全局变量…...

访问者模式

图片转载自 #include<iostream> using namespace std; #include<list> /*模板工厂单例化&#xff0c;所有的商品被注册进工厂中*/ /*访问者模式&#xff08;行为型模式&#xff09; 访问者&#xff0c;被访问者 visit accept 让访问变成一种操作&#xff0c;不同…...

epoll 的实现

epoll 这么好&#xff0c;为什么迟至 2.6 版本的 kernel 才支持(epoll manual: The epoll API was introduced in Linux kernel 2.5.44.)&#xff1f;2.4 版本的 kernel 不支持 epoll&#xff1f; 原因很简单&#xff0c;epoll 没什么神奇的。在早期没有太多的并发连接要处理&…...

怎么用excel管理固定资产

在当今的数字时代&#xff0c;我们已经习惯了使用各种电子工具来提高我们的生产力。其中&#xff0c;Excel无疑是一个强大的工具&#xff0c;它不仅可以帮助我们处理数据&#xff0c;还可以用来进行复杂的计算和分析。然而&#xff0c;你可能不知道的是&#xff0c;Excel也可以…...

记录crack某IDE插件过程

声明&#xff1a;本文仅记录学习过程&#xff0c;已对关键位置脱敏处理&#xff0c;未提供任何工具&#xff0c;请支持正版。 反编译jar包 使用cfr进行对插件核心jar包MyBxxxxxx-obfuss.jar进行反编译&#xff0c;在本地生成a.txt。 java -jar cfr-0.152.jar MyBxxxx-obfuss.…...

Android DEX相关,ART加载OAT文件

android .dex文件,对于Android DEX文件详细说明 Android dex、odex、oat、vdex、art区别 Android下的DEX文件和SO文件梳理总结 Android[art]-Android dex&#xff0c;odex&#xff0c;oat&#xff0c;vdex&#xff0c;art文件结构学习总结 第四章 常见的 Android 文件格式&…...

laravel框架 - 安装初步使用学习 composer安装

一、什么是laravel框架 Laravel框架可以开发各种不同类型的项目&#xff0c;内容管理系统&#xff08;Content Management System&#xff0c;CMS&#xff09;是一种比较典型的项目&#xff0c;常见的网站类型&#xff08;如门户、新闻、博客、文章等&#xff09;都可以利用CM…...

API实战教程:使用身份证OCR识别API构建一个应用

1. 引言 你是否曾经想过&#xff0c;只需拍一张身份证的照片&#xff0c;就能自动读取上面的所有信息&#xff1f;今天&#xff0c;我们要介绍的就是这样一个神奇的工具&#xff1a;身份证OCR识别API。不管你是技术小白还是初学者&#xff0c;跟着我们的步骤&#xff0c;你都可…...

前端-layui动态渲染表格行列与复杂表头合并

说在前面&#xff1a; 最近一直在用layui处理表格 写的有些代码感觉还挺有用的&#xff0c;顺便记录下来方便以后查看使用&#xff1b; HTML处代码 拿到id 渲染位置表格 <div class"layui-table-body salaryTable"><table class"layui-table" i…...

IDM(Internet Download Manager)下载器2024最新版本如何下载?

IDM&#xff08;Internet Download Manager&#xff09;下载器能够兼容支持多种浏览器进行文件下载&#xff0c;很多时候只要复制一个地址IDM的下载弹窗就自动弹出来&#xff0c;有时候不需要下载的时候也会弹&#xff0c;时间久了就会感觉很烦&#xff0c;不过这个问题其实可以…...

前端综合练手小项目

导读 本篇文章主要以小项目的方式展开&#xff0c;其中给出的代码中均包含详细地注释&#xff0c;大家可以参照理解。下面4个小项目中均包含有 HTML、CSS、JavaScript 等相关知识&#xff0c;可以拿来练手&#xff0c;系统提升一下自己的前端开发能力。 废话少说&#xff0c;…...

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器的上位机配置操作说明

LBE-LEX系列工业语音播放器|预警播报器|喇叭蜂鸣器专为工业环境精心打造&#xff0c;完美适配AGV和无人叉车。同时&#xff0c;集成以太网与语音合成技术&#xff0c;为各类高级系统&#xff08;如MES、调度系统、库位管理、立库等&#xff09;提供高效便捷的语音交互体验。 L…...

设计模式和设计原则回顾

设计模式和设计原则回顾 23种设计模式是设计原则的完美体现,设计原则设计原则是设计模式的理论基石, 设计模式 在经典的设计模式分类中(如《设计模式:可复用面向对象软件的基础》一书中),总共有23种设计模式,分为三大类: 一、创建型模式(5种) 1. 单例模式(Sing…...

C++_核心编程_多态案例二-制作饮品

#include <iostream> #include <string> using namespace std;/*制作饮品的大致流程为&#xff1a;煮水 - 冲泡 - 倒入杯中 - 加入辅料 利用多态技术实现本案例&#xff0c;提供抽象制作饮品基类&#xff0c;提供子类制作咖啡和茶叶*//*基类*/ class AbstractDr…...

51c自动驾驶~合集58

我自己的原文哦~ https://blog.51cto.com/whaosoft/13967107 #CCA-Attention 全局池化局部保留&#xff0c;CCA-Attention为LLM长文本建模带来突破性进展 琶洲实验室、华南理工大学联合推出关键上下文感知注意力机制&#xff08;CCA-Attention&#xff09;&#xff0c;…...

工程地质软件市场:发展现状、趋势与策略建议

一、引言 在工程建设领域&#xff0c;准确把握地质条件是确保项目顺利推进和安全运营的关键。工程地质软件作为处理、分析、模拟和展示工程地质数据的重要工具&#xff0c;正发挥着日益重要的作用。它凭借强大的数据处理能力、三维建模功能、空间分析工具和可视化展示手段&…...

Java编程之桥接模式

定义 桥接模式&#xff08;Bridge Pattern&#xff09;属于结构型设计模式&#xff0c;它的核心意图是将抽象部分与实现部分分离&#xff0c;使它们可以独立地变化。这种模式通过组合关系来替代继承关系&#xff0c;从而降低了抽象和实现这两个可变维度之间的耦合度。 用例子…...

Java数值运算常见陷阱与规避方法

整数除法中的舍入问题 问题现象 当开发者预期进行浮点除法却误用整数除法时,会出现小数部分被截断的情况。典型错误模式如下: void process(int value) {double half = value / 2; // 整数除法导致截断// 使用half变量 }此时...

虚拟电厂发展三大趋势:市场化、技术主导、车网互联

市场化&#xff1a;从政策驱动到多元盈利 政策全面赋能 2025年4月&#xff0c;国家发改委、能源局发布《关于加快推进虚拟电厂发展的指导意见》&#xff0c;首次明确虚拟电厂为“独立市场主体”&#xff0c;提出硬性目标&#xff1a;2027年全国调节能力≥2000万千瓦&#xff0…...

如何更改默认 Crontab 编辑器 ?

在 Linux 领域中&#xff0c;crontab 是您可能经常遇到的一个术语。这个实用程序在类 unix 操作系统上可用&#xff0c;用于调度在预定义时间和间隔自动执行的任务。这对管理员和高级用户非常有益&#xff0c;允许他们自动执行各种系统任务。 编辑 Crontab 文件通常使用文本编…...

Caliper 配置文件解析:fisco-bcos.json

config.yaml 文件 config.yaml 是 Caliper 的主配置文件,通常包含以下内容: test:name: fisco-bcos-test # 测试名称description: Performance test of FISCO-BCOS # 测试描述workers:type: local # 工作进程类型number: 5 # 工作进程数量monitor:type: - docker- pro…...