## CSDN博客

### 一种效率极高的分类算法

0100 0001001 0001010 0111000 0000000

2^(N-(N1+N2+…+Ni))*j + 父类编码

2^N-2^(N-(N1+N2+…+Ni))

Create TempCatalog(

[OldID] [int] NOT NULL,

[NewID] [int] NOT NULL,

[OldFatherID] [int] NOT NULL,

[NewFatherID] [int] NOT NULL

);

<%

REM oConn---数据库连接，已经打开

REM OldFather---原来的父类编号

REM NewFather---新的父类编号

REM N---编码总位数

REM Ni--每一级的编码位数数组

REM Level--当前的级数

sub FormatAllID(oConn,OldFather,NewFather,N,Nm,Ni byref,Level)

strSQL = "select CatalogID , FatherID from Catalog where FatherID=" & OldFather

set rsCatalog=oConn.Execute( strSQL )

j = 1

do while not rsCatalog.EOF

i = 2 ^(N - Nm) * j

if Level then i= i + NewFather

OldCatalog = rsCatalog("CatalogID"

NewCatalog = i

REM 写入临时表

strSQL = "Insert into TempCatalog (OldCatalogID , NewCatalogID , OldFatherID , NewFatherID)"

strSQL = strSQL & " values(" & OldCatalog & " , " & NewCatalog & " , " & OldFather & " , " & NewFather & ""

Conn.Execute strSQL

REM 递归调用FormatAllID

Nm = Nm + Ni(Level+1)

FormatAllID oConn,OldCatalog , NewCatalog ,N,Nm,Ni,Level + 1

rsCatalog.MoveNext

j = j+1

loop

rsCatalog.Close

end sub

%>

<%

REM 定义编码参数，其中N为总位数，Ni为每一级的位数。

Dim N,Ni(5)

Ni(1) = 4

N = Ni(1)

for i=2 to 5

Ni(i) = 7

N = N + Ni(i)

next

REM 打开数据库，创建临时表

strSQL = "Create TempCatalog( [OldID] [int] NOT NULL, [NewID] [int] NOT NULL, [OldFatherID] [int] NOT NULL, [NewFatherID] [int] NOT NULL);"

Conn.Open Application("strConn"

Conn.Execute strSQL

REM 调用规格化例程

FormatAllID Conn,-1,-1,N,Ni(1),Ni,0

REM ------------------------------------------------------------------------

REM 在此处更新所有相关表的类别编码为新的编码即可。

REM ------------------------------------------------------------------------

REM 关闭数据库
strSQL= "drop table TempCatalog;"
Conn.Execute strSQL
Conn.Close

%>

Product.FatherID>FID0 and Product.FatherID<FID1

<%

REM oConn---数据库连接，已经打开

REM FID---当前分类

REM FIDMark---特征值数组，典型的情况下为Application(“Mark”)

REM k---数组元素个数，也是分类的级数

Sub GetAllProduct(oConn,FID,FIDMark byref,k)

' 根据FID计算出特征值FID0,FID1

for i=k to 1

if (FID and FIDMark = FID ) then exit

next

strSQL = "select Name from Product where FatherID>"FIDMark(i)&" and FatherID<"FIDMark(i-1)

set rsProduct=oConn.Execute(strSQL)%>

<UL><%

Do While Not rsProduct.Eof%>

<LI><%=rsProduct("Name"

Loop%>

</UL><%

rsProduct.Close

End Sub

%>

0 0