--引用--------------------------------------------------
evanescencex: 祝你 新年快了 。
--------------------------------------------------------
呵呵 有趣 都在比啊
有气氛!TTMP算法 也在写
初学者请教一个问题。我学习了你分享的这几篇好文,也尝试自己组合弄弄,便宜过程中发现一个错误一直想不到解决办法:
###############################
编译器错误信息: CS0246: 找不到类型或命名空间名称“HashSet”(是否缺少 using 指令或程序集引用?)
源错误:
行 17: public class ClearBadword
行 18: {
行 19: private HashSet<string> hash = new HashSet<string>();
行 20: private byte[] fastCheck = new byte[char.MaxValue];
行 21: private byte[] fastLength = new byte[char.MaxValue];
###############################
我的代码前面部分是这样写的:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
/// <summary>
/// ClearBadword 的摘要说明
/// </summary>
public class ClearBadword
{
private HashSet<string> hash = new HashSet<string>();
private byte[] fastCheck = new byte[char.MaxValue];
private byte[] fastLength = new byte[char.MaxValue];
private BitArray charCheck = new BitArray(char.MaxValue);
private BitArray endCheck = new BitArray(char.MaxValue);
private int maxWordLength = 0;
private int minWordLength = int.MaxValue;
========
请指教 谢谢
@fqf
HashSet是.NET 3.5中新增的,如果使用.NET 2.0,可以用Dictionary<string, object>代替。
谢谢博主的回答。
我的是2.0的 所以将原来地方修改了3处:
1;
private Dictionary<string, object> hash = new Dictionary<string, object>();
2;
else
{
fastLength[word[0]] |= (byte)(1 << (Math.Min(7, word.Length - 2)));
endCheck[word[word.Length - 1]] = true;
hash.Add(word, null);
//hash.Add(word);
}
3;
if (hash.ContainsKey(sub))
//if (hash.Contains(sub))
{
return true;
}
不知道这样是否正确,谢谢!
另外,能否麻烦也贴出这个部分内部代码分享一下呢?谢谢。
public override int GetHashCode()
{
// call char.tolower and calculate hash code
}
------------------------
实话,我以前是做java的,现在为了做自己一个网站,考虑服务空间问题,决定学.net来开发,一边学一边用。现在网站对屏蔽敏感词非常必要,而有目的的搜索到你这篇关于高效率过滤的技术文章,内心真的很想一下子能学到并应用进去。可惜自己刚刚接触,无法一时理解大师级的编程精髓,所以,如果博主乐意的话,希望能得到更多的帮助,谢谢! 个人邮箱为 mail@fqf.cn
@fqf
GetHashCode的代码已发到你的邮箱
博主可否给我发一份2.0的,多谢hiying#163.com
看了楼主的这一些列文章,不错。但是缺少注释,可能新手不容易理解哈。
楼主看下,“世纪中国基金会”这个词可以查到,变成“<p>世纪中国基金会世纪中国基金会</p>”就查不到了?是bug吗?