`
歆渊
  • 浏览: 307851 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

Finally made it - A designator tag system for heavy concurrent environment

阅读更多
Download full Source Code here .
public class Designator
extends java.lang.Object
implements java.lang.CharSequence, java.lang.Comparable<java.lang.CharSequence>

This class is designed and implemented to generate printable designator tag strings, with the theoretical target:

Printable
Designator tags are always able to convert to printable strings and vice versa. (via toString() and Designator(CharSequence) constructor)
Comparable
Designator tags or their string representations are comparable to eachother. (via the implemented Comparable interface or the Designator.DesignatorComparator class)
Insertable at Any Position
Given two designator tags: lower and upper, if lower.compareTo(upper) < 0 is true, then it is always possible to generate a new tag middle that between lower and upper, so lower.compareTo(middle) < 0 and upper.compareTo(middle) > 0 will both be true.

This class is so used to resolve sorting problems of sibling WoW nodes. Since WoW is web based thus allow concurrent modifications including inserting child nodes to a same parent node, maybe by many different users at the same time. And WoW use database instead of linear storage to store node data, so the sorting order of sibling nodes became quite unobvious. Using an integer number as the unique sequence number seems feasible but there will be situations when insert a new node between nodes designated by two integers that one directly follows another. Think about insert between 7 and 8, yes we can change the old 8 node's seq no to 9 and make the newly inserted 8. But there may already been 9, 10, 11 ... stand, in the worst case we'll have to modify all succeeding sibling nodes, as sequence numbers have to be persistent attributes, this will raise heavy concurrent contention risk.

Finally we need an sequencing schema that both allow random insertion at arbitrary positions and rarely need to change saved data. Then this class come into idea inspired by fractional arithmetic of the positional number system. You can find infinite numbers of fractional numbers between two of them. But that will produce more digits when these two number are very close, and the increase of digits is also infinite.

To determin whether a simular mechanism is suitable for WoW daily use, some estimation are made with this class, and the result shows the number of digits will exceed 250 only after randomly insert more than one million nodes under a particular one, since 250 is a reasonable tag length for modern data systems, it seems fairly feasible.

Technically, this class simulates a signed fractional number system with a base of 64. We use a single byte to store each digit value, this wastes 25% of the memory space but should be practically acceptable since it also improves the processing time performance. We use ASCII 0-9 A-Z a-z and { } as the digit symbols, and place them in their ASCII order, this simplifies and boosts comparation against string representations of designator tags.

Below are some estimation results produced by running the main(String[]) method.

 Firing 30000 random insert session with each 100 records at max.
 Designator length exceeds 250 after fired 23486 insert sessions and inserted 1178115 records.
 -------------------------------------------------
 Total inserted designators: 1504340
 Longest one is [257]: +}}}}}}}}}}}}}}v03000000000000030000000F0E}}}}}{F00000}}}}}}y000000300000EU}}}}}}}x}}}Vw}{00002}}}}}}}}}}}x{00002}}}}}}}}}}}}}W00000000000000102l0000000002}}}}}}}}}}}x}}Vw{000000000000002}}}{00000V000030000000000}}{000000E}}}}}}}}}}t}}}}}}}}}}}000000000000V
 Average length: 117
 Length above 2: 349 => 0‰
 Length above 4: 1457 => 0‰
 Length above 8: 7511 => 4‰
 Length above 16: 41436 => 27‰
 Length above 32: 145931 => 97‰
 Length above 64: 657302 => 436‰
 Length above 128: 650346 => 432‰
 Length above 256: 8 => 0‰
 Length above 512: 0 => 0‰
 Errors: 0
 
 Firing 30000 random insert session with each 100 records at max.
 Designator length exceeds 250 after fired 22650 insert sessions and inserted 1137011 records.
 -------------------------------------------------
 Total inserted designators: 1503406
 Longest one is [335]: -}}}}}}}}}}}}}}}}}}}}}}TlU}}}}}}}}}}}}}}}u00000000000100000000000000010000000U}}}}}}}y00000000000E}}}W0000U}}}}}}}}}l}}u00F000700F02}}}}V}}}}}}}}}V}}}}00000000000000002}}}}}}}}}}W00000000000000030000000000V02}}}}}}}}}}}}u000000000000000000}}}}}}}z}}}}}}}}y000000000000000002}}}{}}}}}}}}}}}}}{}}}}}}}}}00000000006}}}}}}}}}}}00000000000V
 Average length: 140
 Length above 2: 349 => 0‰
 Length above 4: 1381 => 0‰
 Length above 8: 6133 => 4‰
 Length above 16: 34476 => 22‰
 Length above 32: 199236 => 132‰
 Length above 64: 348206 => 231‰
 Length above 128: 847748 => 563‰
 Length above 256: 65877 => 43‰
 Length above 512: 0 => 0‰
 Errors: 0
 
 Firing 30000 random insert session with each 100 records at max.
 Designator length exceeds 250 after fired 25835 insert sessions and inserted 1293752 records.
 -------------------------------------------------
 Total inserted designators: 1504246
 Longest one is [265]: +gl00V000000000000U}}}}{}}}}}}}}}}}}}{000000000000E}}}}z}}}}}{00000000000013002}}}}}u0000000000000000}}}}}}}}}}}}z}}}}}}}}{00000F0002zs}}{0000010000000000V000000000000003000000V000E}}}}}}z}}}}t}}}}}}z}m0000006}}}}}V}}{000001000000000000000030000000000E}}}}}}}}}}}}W
 Average length: 111
 Length above 2: 335 => 0‰
 Length above 4: 2101 => 1‰
 Length above 8: 12525 => 8‰
 Length above 16: 76643 => 50‰
 Length above 32: 302603 => 201‰
 Length above 64: 527695 => 350‰
 Length above 128: 582167 => 387‰
 Length above 256: 177 => 0‰
 Length above 512: 0 => 0‰
 Errors: 0
 
 
分享到:
评论

相关推荐

    cld:符合C99的编译器

    cld-C99编译器cld是使用C ++编写的完全兼容C99(少有错误)的编译器。 前端是从头开始编写的,并且LLVM当前用作代码生成的后端。 命令行界面旨在匹配GCC之一,但目前仍在工作。 当前支持的代码生成目标是Windows和...

    Altium Designer(AD) Assembly装配图元件Designator标注终极教程.doc

    本教程主要讲述的是在Altium Designer中进行装配图(Assembly Drawing)的设计与元件标识(Designator)的标注,特别是在批量处理和样机手工焊接装配图生成方面的方法和技巧。 ### 知识点1:机械层对...

    NativeXml-master

    Made check for UTF-8 case insensitive * Fixed bug with stringtable (removed "gaps") + Added AttributeValueDirect prop Version 2.31 (03May2007) * Verified compatibility with Delphi2 and 3 * Fixed 2 ...

    STM32F103C8T6最小系统板原理图,PCB文件ad版本Altium Designer版本工程文件

    | Comment | Description | Designator | Footprint | |---------------|-------------------------|----------------------------|-----------------| | 1uF/0603 | 无极性电容 | C1, C4, C11, C12, C13, C14 | ...

    AD10快捷键

    * 可将一个元件库分为两个 Part,例如 parta, partb(通过 Tools-&gt;new part) ### pcb 库 * File-&gt;New-&gt;Library-&gt;pcb.. * 右边下方 PCB 打开 pcb Library 窗口 * IPC FootPrint wizard..(比较有用) * 画图要焊盘...

    i4电路原理图

    | PART NUMBER | ALTERNATE FOR | PART NUMBER | BOM OPTION | REFDES | COMMENTS | |-------------|---------------|-------------|------------|--------|----------| | 101 | 替换电阻 | 102 | Option A | R1 | |...

    Protel99se布线经验

    - 在Protel99SE中选择“Preferences”,取消勾选“Use Client system Font For All Dialogs”。 #### 二、基本操作技巧 1. **颜色设置** - 使用快捷键“O-O”(Option-Color)来调整PCB各层的颜色。 2. **原点...

    Altium_Designer_6_--一点总结

    - 右下角的System按钮:打开不同面板 - Ctrl+Tab:在不同窗口间切换 - Ctrl+鼠标中键滚轴:放大和缩小视图 4. 设计工具: - DeSign-Template-Set Template File Name...:设置模板文件 - Modify右下方的边框:...

    altium designer 18 PCB全流程设计书册

    - 确定器件的位号:双击器件名,修改 Default Designator,通常设置为(x?)。 - 确定器件的元素:双击器件名,设置 Default Comment,如“电源端子”或“PWR”。 - 关于器件原理图的绘制和引脚定义(略)。 - ...

    《EDA技术及应用》实验指导书21

    这里主要涉及到的是图纸大小的设定,推荐使用A4纸张大小(见图4),这样便于后续打印和查看。 **3. 载入元件库** 实验所需的元件及其对应的库信息如下: | 元件在图中标号 | 元件图形样本名 | 所在元件库 | 标示...

    altium designer使用技巧汇总.docx

    - **System → General**:系统级别的通用设置,例如单位、字体等。 - **System → View**:视图设置,如网格样式、背景颜色等。 - **PCB Editor → General → 对象捕捉选项**:设置捕获对象的方式,通常推荐全选以...

    altium利用EXCEL自动生成元件信息.pdf

    | Object | Kind | X1 | Y1 | Orientation | Name | Symbol | Electrical Type | Pin Designator | |--------|------|------|------|-------------|----------|---------|----------------|----------------| | Pin ...

    Mentor Graphics快捷操作

    - 示例:`pr-pxy=0,0100018.0-a=90.0u1:20` 在原点周围放置20个`u1`器件,半径1000mil,角度增量18度,起始角度90度。 38. **Place Component at Coordinate with Angle (`pr&lt;coord&gt;{-angle=angle}refdes`)** - ...

    micron dram number guideline

    - **-A**:表示未测试; - **-25**:表示DDR3 SDRAM 400MHz,时序6-6-6/-5-5-5; - **-187**:表示533MHz,时序8-8-8/-7-7-7/-6-6-6; - **-15**:表示667MHz,时序10-10-10/-9-9-9/-8-8-8; - **-125**:表示...

    locales-list:ISO 639-1,ISO 639-1和ISO 3166-1的语言环境列表

    语言环境列表 ISO 639-1,ISO 639-1和ISO 3166-1的语言环境列表。 注意 该库不是可靠的完整库或综合库。 该软件包的数据是从两个软件包中收集的:来自数据的带有国家地区代码的区域设置以及来自的国家。...

    基于RFID的档案管理系统-RFIDx4材料清单.pdf

    - **Footprint**: SMB(DO-214AA)-A。 - **用途**: 用于整流、保护电路等场合。 **1uH 贴片电感** - **Quantity**: 8个。 - **Footprint**: L0805。 - **用途**: 用于滤波、扼流等应用,尤其是电源部分。 **15uH ...

    A了tium designer

    - **Designator Display**:设置是否显示元件的物理或逻辑标号,有助于识别不同元件。 - **设定原点**:通过“Edit \ Origin \ Set”命令,在PCB上设定一个原点作为参考点。 - **设定边框**: - 使用“Design \ ...

Global site tag (gtag.js) - Google Analytics