软件体系结构经典问题——KWIC的分析和解决
2014-01-10 23:15 youxin 阅读(7718) 评论(0) 编辑 收藏 举报KWIC作为一个早年间在ACM的Paper提出的一个问题,被全世界各个大学的软件设计课程奉为课堂讲义或者作业的经典。(From Wiki,FYI,D. L. Parnas uses a KWIC Index as an example on how to perform modular design in his paper "On the Criteria To Be Used in Decomposing Systems into Modules" - Available as ACM Classic Paper)
问题陈述:KWIC(Key Word In Context),Parnas (1972)
KWIC索引系统接受一些行,每行有若干字,每个字由若干字符组成;每行都可以循环移位,亦即重复地把第一个字删除,然后接到行末; KWIC把所有行的各种移位情况按照字母表顺序输出

•目的:考察不同的体系结构对变化的适应能力(modifiability)
•评价准则
–处理算法的改变:例如,行的移位可在每行读入后、在所有行读入后、或当排序要求一组移位的行时執行;
–数据表示的改变:例如,行、字、字符可以不同的方式存储;类似地,循环移位后的行可以显式或隐式存储(索引和偏移量);
–系统功能的增强:例如,限制以某些“修饰词”(a, an, and等)打头的移位结果;支持交互,允许用户从原始输入表中删除一些行等;
–效率:时间和空间;
–复用:构件被复用的潜力。
Solution 1:
Main Program/Subroutine with Shared Data
Main Program/Subroutine with Shared Data
Elements of Main/Subroutine Architectural style are:
- Components: Functions
- Interactions: Function calls
- Pattern: Main function controls the calling sequence
•Decompose the overall processing into a sequence of processing steps.
–Read lines; Make shifts; Alphabetize; Print results
•Each step transforms the data completely.
每一步完全转换数据
每一步完全转换数据
•Intermediate data stored in shared memory.
–Arrays of characters with indexes
带索引的字符数组
带索引的字符数组
–Relies on sequential processing
串行处理
串行处理

Solution 1:Modularization
•Module 1: Input
–Reads data lines and stores them in “core”.
–Storage format: 4 chars/machine word; array of pointers to start of each line.
–
•Module 2: Circular Shift
–Called after Input is done.
–Reads line storage to produce new array of pairs: (index of 1st char of each circular shift, index of original line)
–
•Module 3: Alphabetize
–Called after Circular Shift.
–Reads the two arrays and produces new index.
•Module 4: Output
–Called after alphabetization and prints nicely formatted output of shifts
–Reads arrays produced by Modules 1 & 3
–
•Module 5: Master Control
–Handles sequencing of the first 4 modules
–Handles errors
Properties of Solution 1
•Batch sequential processing.
•Uses shared data to get good performance.
用共享数据获得性能
用共享数据获得性能
•Processing phases handled by control module.
–So has some characteristics of main program – subroutine organization.
–Depends critically on single thread of control.
•Shared data structures exposed as inter-module knowledge.
共享数据的结构是所有模块必须知道的
共享数据的结构是所有模块必须知道的
–Design of these structures must be worked out before work can begin on those modules.
数据结构的设计必须在其他模块设计开始之前进行
数据结构的设计必须在其他模块设计开始之前进行
方案优缺点:
+系统自然分解,符合人的处理习惯
+数据共享,处理效率高
+
–难以适应数据存储格式和整体处理算法的变化——爲什麽?
–系统构件难以支持复用——爲什麽?
仔细参考:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
2013-01-10 VC中调用外部程序的几种方法
2013-01-10 (转)MFC技巧学习
2013-01-10 使用MFC中的CDC,CBitmap来实现贴图
2013-01-10 mfc error C2501: 'GetDocument' : missing storage-class or type spec