<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Terence的窝</title>
	<atom:link href="http://terence2008.info/feed" rel="self" type="application/rss+xml" />
	<link>http://terence2008.info</link>
	<description>人生如戏院，为了在喧哗中被人听见，有时候得学会轻声说话...</description>
	<lastBuildDate>Wed, 22 Feb 2017 14:38:43 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AjaxSwing4.4.0授权码</title>
		<link>http://terence2008.info/archives/ajaxswing.html</link>
		<comments>http://terence2008.info/archives/ajaxswing.html#comments</comments>
		<pubDate>Wed, 22 Feb 2017 14:38:43 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[网页]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=560</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; AjaxSwing是一种在运行时自动转换<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/java" title="查看 Java 的全部文章">Java</a></span> Swing/AWT桌面应用程序到Ajax网站的解决方案，可以被看成是<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/java" title="查看 Java 的全部文章">Java</a></span>桌面应用的HTML转换。它允许开发者使用标准Swing组件来实现Web用户界面，而不必改变现有的Swing窗体和业务逻辑，也不需要程序员学习任何<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/java" title="查看 Java 的全部文章">Java</a></span>和Swing核心之外的API，通过HTML/JavaScript的自动转换使桌面应用焕发第二春。</p>
<p>&nbsp; &nbsp; &nbsp; AjaxSwing在官网提供了免费版的下载，但存在以下一些限制：</p>
<p>1、用户并发数限制为5</p>
<p>2、Web页面上有AjaxSwing的水印，<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%bd%91%e9%a1%b5" title="查看 网页 的全部文章">网页</a></span>标题后面有尾巴</p>
<p>3、限制Web应用部署量为3个</p>
<p>4、一些自定义渲染/过滤器的限制</p>
<p>5、会采集汇报用户信息</p>
<p>&nbsp; &nbsp; &nbsp; 具体的限制以及授权定价可以<a href="http://www.creamtec.com/products/ajaxswing/prices.html" target="_blank">参见这里</a>，只能说价格好黑，还额外按cpu核收费，你当自己是Oracle么？内心不安分的想法又出来鸟~软件自由万岁！软件破解过程就不详细讲了，反正算法挺简单的，而且代码也没有混淆，半小时左右就搞定，说下授权码使用方法：</p>
<p>1、进入AjaxSwing4.4.0/conf目录</p>
<p>2、创建ajaxswing.lic文件，写入 &nbsp;lic=810534314-50000990-3:::.23.42</p>
<p>3、重启应用，done！</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="AjaxSwing4.4.0授权码" href="http://terence2008.info/archives/ajaxswing.html">《AjaxSwing4.4.0授权码》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/javamail_on_jdk8_ssl_problem.html" title="Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案">Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案</a> (0)</li><li><a href="http://terence2008.info/archives/spring_in_jdk_classes_loding_bug.html" title="Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题">Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题</a> (1)</li><li><a href="http://terence2008.info/archives/hibernate_criteria_order.html" title="Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作">Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作</a> (2)</li><li><a href="http://terence2008.info/archives/eclipse-optimizing.html" title="Eclipse性能优化实践">Eclipse性能优化实践</a> (0)</li><li><a href="http://terence2008.info/archives/thesis.html" title="浅谈不同浏览器地址栏中编码的差异">浅谈不同浏览器地址栏中编码的差异</a> (2)</li><li><a href="http://terence2008.info/archives/google-adsense.html" title="巧用Google AdSense赚美元">巧用Google AdSense赚美元</a> (1)</li><li><a href="http://terence2008.info/archives/tinymce-firefox.html" title="TinyMCE编辑器对FireFox的兼容不太好">TinyMCE编辑器对FireFox的兼容不太好</a> (1)</li><li><a href="http://terence2008.info/archives/013.html" title="Google阅读器里RSS的显示问题">Google阅读器里RSS的显示问题</a> (0)</li><li><a href="http://terence2008.info/archives/010.html" title="网页中连续字符手动换行的方法">网页中连续字符手动换行的方法</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/ajaxswing.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案</title>
		<link>http://terence2008.info/archives/javamail_on_jdk8_ssl_problem.html</link>
		<comments>http://terence2008.info/archives/javamail_on_jdk8_ssl_problem.html#comments</comments>
		<pubDate>Mon, 26 Dec 2016 10:50:00 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JVM]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=557</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 最近开发了一个工具，其中一个模块的功能是通过javamail发送邮件到指定地址，采用的smtp服务器是QQ邮箱（smtp.qq.com:465）。在本机自测功能的时候都是OK的，但在用户机器上执行发送邮件时却抛错了，查看了下异常信息，报的是javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure，这就意味着在建立ssl连接的时候加密套件协商失败。查看了下双方的JDK版本发现我的机器上运行的是JDK6，而用户运行的是JDK8，JDK8默认禁用了一些被认为不安全的加密套件，而QQ邮箱却强制使用了那些不安全的加密套件。JDK版本的不同导致的差异原因具体可以参见<a href="http://www.xiaotanzhu.com/2016/07/30/use-rc4-in-tencent-mail.html" target="_blank">这里</a>。</p>
<p>&nbsp; &nbsp; &nbsp; 通过那篇博文提到的方法，我们可以发现要解决这个恶心的QQ邮箱RC4算法不兼容JDK8的问题只能替换JDK目录下的jce配置文件，但这种方法太过于本地化，无法将该解决方案应用到实际客户机上。因此再接着找方案，终于找到一个靠谱的，见<a href="http://stackoverflow.com/questions/1179672/how-to-avoid-installing-unlimited-strength-jce-policy-files-when-deploying-an/22492582#22492582" target="_blank">这里</a>，大致的意思就是通过反射获取那些定义安全限制的jce类，并做修改。我用这个方法测试后发现的确有效，但期间牵扯出另一个问题，就是从JDK8U102开始，javax.crypto.JceSecurity的isRestricted成员被修饰成了final属性，具体bug描述请见<a href="https://bugs.openjdk.java.net/browse/JDK-8149417" target="_blank">这里</a>，这导致很多网站互相转载的所谓jce反射修改方案实际运行时会抛错：Can not set static final boolean field javax.crypto.JceSecurity.isRestricted to java.lang.Boolean，而我找到的那篇Stackoverflow上的回复却很好的解决了这个问题。</p>
<p>&nbsp; &nbsp; &nbsp; 为了让代码看起来更容易理解，以及使用上的方便，我改进了去除JDK8安全限制的方法。JAVA类如下：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.reflect.Field</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.lang.reflect.Modifier</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.Permission</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.security.PermissionCollection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Map</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RemoveCryptographyRestrictions <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">volatile</span> <span style="color: #000000; font-weight: bold;">static</span> RemoveCryptographyRestrictions INSTANCE<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>INSTANCE<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">synchronized</span> <span style="color: #009900;">&#40;</span>RemoveCryptographyRestrictions.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>INSTANCE<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
                    INSTANCE<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">new</span> RemoveCryptographyRestrictions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> RemoveCryptographyRestrictions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
        Class<span style="color: #339933;">&lt;?&gt;</span> jceSecurity <span style="color: #339933;">=</span> getClazz<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.crypto.JceSecurity&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Class<span style="color: #339933;">&lt;?&gt;</span> cryptoPermissions <span style="color: #339933;">=</span> getClazz<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.crypto.CryptoPermissions&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Class<span style="color: #339933;">&lt;?&gt;</span> cryptoAllPermission <span style="color: #339933;">=</span> getClazz<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;javax.crypto.CryptoAllPermission&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>jceSecurity<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">||</span>cryptoPermissions<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">||</span>cryptoAllPermission<span style="color: #339933;">==</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">return</span><span style="color: #339933;">;</span>
        setFinalStaticValue<span style="color: #009900;">&#40;</span>jceSecurity, <span style="color: #0000ff;">&quot;isRestricted&quot;</span>, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">PermissionCollection</span> defaultPolicy <span style="color: #339933;">=</span> getFieldValue<span style="color: #009900;">&#40;</span>jceSecurity, <span style="color: #0000ff;">&quot;defaultPolicy&quot;</span>,  <span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #003399;">PermissionCollection</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Map<span style="color: #339933;">&lt;?</span>, <span style="color: #339933;">?&gt;</span> map<span style="color: #339933;">=</span>getFieldValue<span style="color: #009900;">&#40;</span>cryptoPermissions, <span style="color: #0000ff;">&quot;perms&quot;</span>, defaultPolicy, <span style="color: #003399;">Map</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        map.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">Permission</span> permission<span style="color: #339933;">=</span>getFieldValue<span style="color: #009900;">&#40;</span>cryptoAllPermission, <span style="color: #0000ff;">&quot;INSTANCE&quot;</span>, <span style="color: #000066; font-weight: bold;">null</span>, <span style="color: #003399;">Permission</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        defaultPolicy.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>permission<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> Class<span style="color: #339933;">&lt;?&gt;</span> getClazz<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> className<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Class<span style="color: #339933;">&lt;?&gt;</span> clazz<span style="color: #339933;">=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            clazz<span style="color: #339933;">=</span><span style="color: #000000; font-weight: bold;">Class</span>.<span style="color: #006633;">forName</span><span style="color: #009900;">&#40;</span>className<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> clazz<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">void</span> setFinalStaticValue<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;?&gt;</span> srcClazz, <span style="color: #003399;">String</span> fieldName, <span style="color: #003399;">Object</span> newValue<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">Field</span> field<span style="color: #339933;">=</span>srcClazz.<span style="color: #006633;">getDeclaredField</span><span style="color: #009900;">&#40;</span>fieldName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        field.<span style="color: #006633;">setAccessible</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">Field</span> modifiersField <span style="color: #339933;">=</span> <span style="color: #003399;">Field</span>.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getDeclaredField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;modifiers&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        modifiersField.<span style="color: #006633;">setAccessible</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        modifiersField.<span style="color: #006633;">setInt</span><span style="color: #009900;">&#40;</span>field, field.<span style="color: #006633;">getModifiers</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> ~<span style="color: #003399;">Modifier</span>.<span style="color: #000000; font-weight: bold;">FINAL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        field.<span style="color: #006633;">set</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">null</span>, newValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> T getFieldValue<span style="color: #009900;">&#40;</span>Class<span style="color: #339933;">&lt;?&gt;</span> srcClazz, <span style="color: #003399;">String</span> fieldName, <span style="color: #003399;">Object</span> owner, Class<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">&gt;</span> dstClazz<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">Field</span> field<span style="color: #339933;">=</span>srcClazz.<span style="color: #006633;">getDeclaredField</span><span style="color: #009900;">&#40;</span>fieldName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        field.<span style="color: #006633;">setAccessible</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> dstClazz.<span style="color: #006633;">cast</span><span style="color: #009900;">&#40;</span>field.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>owner<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 使用方法非常简单，只要在你的程序的入口位置加入RemoveCryptographyRestrictions.init();就完成啦~</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案" href="http://terence2008.info/archives/javamail_on_jdk8_ssl_problem.html">《Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/spring_in_jdk_classes_loding_bug.html" title="Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题">Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题</a> (1)</li><li><a href="http://terence2008.info/archives/ajaxswing.html" title="AjaxSwing4.4.0授权码">AjaxSwing4.4.0授权码</a> (2)</li><li><a href="http://terence2008.info/archives/hibernate_criteria_order.html" title="Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作">Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作</a> (2)</li><li><a href="http://terence2008.info/archives/eclipse-optimizing.html" title="Eclipse性能优化实践">Eclipse性能优化实践</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/javamail_on_jdk8_ssl_problem.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>分享自己做的Kindle3交叉编译工具链</title>
		<link>http://terence2008.info/archives/kindle3_cross_chaintool.html</link>
		<comments>http://terence2008.info/archives/kindle3_cross_chaintool.html#comments</comments>
		<pubDate>Mon, 28 Dec 2015 11:23:36 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[kindle]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=555</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 最新突然兴起想要在k3上跑一些c/c++项目的程序，可惜光有源码没有编译工具很是头疼。找了一大圈Google就是没找到一个合适的现成的交叉编译工具链，不是Glibc版本过低，就是arm目标平台不符合，最后只好放弃这个偷懒的方法（其实已经算不上偷懒了，在找交叉编译工具链上已经花了大量的时间精力。。。），取而代之的方法就是直接源码编译交叉编译工具链呗。</p>
<p>&nbsp; &nbsp; &nbsp; 看了下网上关于工具链源码编译的方法还是挺多的，本着哪个方便就用哪个的原则，我发现了一个编译神器：crosstool-ng，这玩意儿本身也是需要源码编译，依赖bison gperf flex texinfo libtool ncurses-libs ncurses-devel gawk gcc gcc-c++ gcc-java glibc glibc-common libc-client-devel libc-client glibc-devel glibc-static glibc-utils (确切地说是编译GCC要用)，使用方法照着文档说明就行，主要就是要生成一个config文件，里面定义了要编译的各个组件的版本以及目标平台、是否为交叉编译等，这个工具还提供了一个命令行下的图形界面来对编译配置文件进行增删改查，非常的赞，当然如果随便配置的话很有可能会编译不成功的。官方网站<a href="http://crosstool-ng.org/" target="_blank">点此进入</a>，简略的使用方法见下：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ct-ng menuconfig <span style="color: #666666; font-style: italic;"># 启动可视化界面，Load/modify Config文件</span>
ct-ng build <span style="color: #666666; font-style: italic;"># 开始编译toolchains</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; k3的crosstool-ng配置文件在mobileread论坛上有分享，所以也不用自己劳神配置，不过我还是稍微修改了些地方（isl版本过高导致后面的编译失败），文件我会包含在下面的下载链接里。最后的build过程还是比较顺利的，双核2G内存虚拟机用了大概40多分钟就全部完成了，注意编译时不能在root用户的shell下进行，否则会通不过检查。编译完成后会在同级目录下生成x-tools目录，里面躺着的就是交叉编译工具链啦~配置下环境变量即可使用。下面的链接就是完整的k3交叉编译工具链了，赶紧来个Hello world试试吧~（鉴于linux平台的多样性，我只能保证交叉编译工具链在centos 6.5 x86-64下运行正常，这也是为什么网上鲜有现成工具下载的原因）。</p>
<h2>附件在此：</h2>
<p><a title="最后下载:2026年03月10日,下载232次" href="http://terence2008.info/downloads/arm-kindle-linux-gnueabi.7z" target="_blank">arm-kindle-linux-gnueabi.7z</a></p>
<p>&nbsp; &nbsp; &nbsp; 另外我还发现oracle java8下载页面里的那个arm平台的jdk真的可以在k3上跑的起来，<a href="http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html" target="_blank">链接在此</a>，选择Linux ARM v6/v7 Hard Float ABI平台就是。这样在kindle3下我就可以欢快地跑Java和C程序啦！</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="分享自己做的Kindle3交叉编译工具链" href="http://terence2008.info/archives/kindle3_cross_chaintool.html">《分享自己做的Kindle3交叉编译工具链》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/kindle3_launchpad.html" title="适用于Kindle 3 原生系统3.4.2 的Launchpad热键管理程序">适用于Kindle 3 原生系统3.4.2 的Launchpad热键管理程序</a> (0)</li><li><a href="http://terence2008.info/archives/kindle3_pinyin_input_method.html" title=" [完美版发布！] Kindle 3 原生系统3.4.2拼音输入法完美版安装包[最新版本0.4.2]"> [完美版发布！] Kindle 3 原生系统3.4.2拼音输入法完美版安装包[最新版本0.4.2]</a> (19)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/kindle3_cross_chaintool.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>适用于Kindle 3 原生系统3.4.2 的Launchpad热键管理程序</title>
		<link>http://terence2008.info/archives/kindle3_launchpad.html</link>
		<comments>http://terence2008.info/archives/kindle3_launchpad.html#comments</comments>
		<pubDate>Sat, 31 Oct 2015 14:03:55 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[kindle]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=553</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; Launchpad是适用于Kindle 3的快捷键管理程序，就是以指定的键盘按键（或键盘组合）来快速运行特定程序或命令，它非常的实用且轻量，后台就一个常驻进程，内存占用小。可是自从原生系统更新到3.4.1后，Launchpad的安装包拷贝到Kindle根目录下后，“Update Your Kindle”这个选项始终处于不可选状态，表现的情况和当时我做的拼音输入法安装包0.4.1版一致，详情<a href="http://terence2008.info/archives/kindle3_pinyin_input_method.html" target="_blank">点击这里</a>。</p>
<p>&nbsp; &nbsp; &nbsp; 究其原因是由于3.4.1后Amazon更新了OTA升级包的版本标识，导致用了老的打包程序在新的固件系统上识别不出来。原理清楚后解决方法就很容易了，只要把原来的安装包解开，然后用新的打包程序生成下就可以使用了。可正当我打包完新安装包后，回头去看了下mobileread论坛，暮然发现原来那个发布Launchpad的帖子里已经有热心的朋友抢先在9月份就发布0.0.1d版本的新安装包了，更新说明和我现在做的如出一辙。好吧，看来我不用多操心了，直接放上论坛地址供有需要的朋友下载吧，帖子地址<a href="http://www.mobileread.com/forums/showthread.php?t=97636" target="_blank">点击这里</a>，下载文件lpad-pkg-001d.zip，然后里面的安装包如何使用就不再赘述了。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="适用于Kindle 3 原生系统3.4.2 的Launchpad热键管理程序" href="http://terence2008.info/archives/kindle3_launchpad.html">《适用于Kindle 3 原生系统3.4.2 的Launchpad热键管理程序》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/kindle3_cross_chaintool.html" title="分享自己做的Kindle3交叉编译工具链">分享自己做的Kindle3交叉编译工具链</a> (1)</li><li><a href="http://terence2008.info/archives/kindle3_pinyin_input_method.html" title=" [完美版发布！] Kindle 3 原生系统3.4.2拼音输入法完美版安装包[最新版本0.4.2]"> [完美版发布！] Kindle 3 原生系统3.4.2拼音输入法完美版安装包[最新版本0.4.2]</a> (19)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/kindle3_launchpad.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[完美版发布！] Kindle 3 原生系统3.4.2拼音输入法完美版安装包[最新版本0.4.2]</title>
		<link>http://terence2008.info/archives/kindle3_pinyin_input_method.html</link>
		<comments>http://terence2008.info/archives/kindle3_pinyin_input_method.html#comments</comments>
		<pubDate>Sat, 11 Jul 2015 14:54:58 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[kindle]]></category>
		<category><![CDATA[拼音输入法]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=541</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; &nbsp;由于百度Hi空间的寿终正寝，原来发在上面的关于kindle3原生系统3.4.1<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%8b%bc%e9%9f%b3%e8%be%93%e5%85%a5%e6%b3%95" title="查看 拼音输入法 的全部文章">拼音输入法</a></span>的帖子随之消失的一干二净，故不得不转载自己的帖子到自己的博客里了。吐槽下，本来好好的产品就这样被糟蹋了 <img src='https://terence2008.info/wp-includes/images/smilies/icon_confused.gif' alt=':???:' class='wp-smiley' />  。</p>
<p>*************************************************</p>
<h2>2015.7.17针对<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/kindle" title="查看 kindle 的全部文章">kindle</a></span> 3更新官方固件到3.4.2的说明</h2>
<p>&nbsp; &nbsp; &nbsp; &nbsp;距上次1月份官方固件更新到3.4.1后，今年的6月下旬又紧接着出来了3.4.2版，时隔5个月，虽然官方说这是一次普通的bug修复升级，但通过逆向分析更新包后发现实际上还是更新了有149个系统文件之巨，<a href="http://www.amazon.com/gp/help/customer/display.html?nodeId=200529700" target="_blank">官网链接在此</a>。不过好在这些更新并不影响<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%8b%bc%e9%9f%b3%e8%be%93%e5%85%a5%e6%b3%95" title="查看 拼音输入法 的全部文章">拼音输入法</a></span>0.4.2版的正常工作，已手工测试通过该版本的安装和卸载，请大家放心使用。</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp;需要提醒的是，在更新官方固件3.4.2的时候需要先卸载拼音输入法，否则更新固件时会报失败，具体安装卸载的方法见下面的说明。</p>
<p>*************************************************</p>
<h2>2015.3.24拼音输入法更新到0.4.2版，以适配官方固件3.4.1</h2>
<p>&nbsp; &nbsp;&nbsp; &nbsp; Amazon时隔2年多，于今年的1月份对<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/kindle" title="查看 kindle 的全部文章">kindle</a></span> 3进行了一次小版本更新，更新到了3.4.1，修复了openssl相关的bug。而正是因为此次更新导致了拼音输入法安装包再一次不能使用了。经过排查，现定位到Amazon对ota更新包的打包格式有了比较严格的限定，之前的打包不符合要求，所以导致了home-menu-Setting-menu-Update Your Kindle选项始终为不可选状态。现在已经将文件重新打包发布，朋友们可以直接用0.4.2版的安装文件，安装方式不变。</p>
<p>enjoy！</p>
<p>*************************************************</p>
<p>&nbsp; &nbsp;&nbsp; &nbsp; Hi，朋友们！大家一定等的很辛苦吧，时隔半年，终于发布了适用于kindle3原生固件3.4版的拼音输入法完美版OTA安装包。在之前的帖子中我也提到过Amazon的此次更新对整个GUI界面进行了代码重构，而且发布的Java运行文件又是经过混淆的，这就导致了拼音输入法的升级开发工作屡屡受阻，所以一开始我只能先发布了存在不少bug的不完美版手动安装包给大家应急，随后又发布了不完美版的OTA安装包。</p>
<p>&nbsp; &nbsp;&nbsp; &nbsp; 此次完美版的发布不得不感谢一位不知名大神的启发，他受了wall_john朋友的委托，率先研究出了dirty hack方法，定位到了导致bug发生的代码位置，但可惜的是他只发布了适用于3g版的安装包，而且并没有公布具体的解决方法，安装包也较为臃肿。所以我只能对他的破解工作做了逆向分析，并最终发布了这个适用于k3所有系列的完美版。在此我还是要特别感谢这位朋友的无声帮助，因为在逆向分析的过程中，我发现无论是反编译的工作量还是bug的代码定位，所花费的精力都是巨大的。当然也还是要感谢此拼音输入法最初版的设计开发者canbefound大神，是他的努力给了我们爱折腾一族无限的惊喜！</p>
<p>&nbsp; &nbsp;&nbsp; &nbsp; 废话说了这么多，以下就是安装方法和说明，想直接安装的朋友就请忽略上面吧 <img src='https://terence2008.info/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  。</p>
<h2>安装方法：</h2>
<p>1.和其他第三方Hack的安装包一样，越狱是安装的前提，从&nbsp;<a href="http://www.mobileread.com/forums/showthread.php?t=88004" target="_blank">http://www.mobileread.com/forums/showthread.php?t=88004</a>下载kindle-jailbreak-0.13.N.zip，然后从压缩包中选择与自己机型相符的update_jailbreak_0.13.N_*_install.bin（k3g-美版3G版K3；k3gb-英版3G版K3；k3w-WIFI版K3），将其放在USB根目录下，之后home-menu-Setting-menu-Update Your Kindle-OK，即可完成越狱。</p>
<p>2.越狱成功之后，根目录下会多出一个linkjail文件夹，里面保存的是越狱程序的所需文件和配置信息，要想安装输入法，必须对设置进行一下修改。我们所需要的修改是linkjail/etc/whitelist，也就是白名单，需要在whitelist的文件首添加一行需要放行的安装包前缀，而输入法安装包的前缀是：update_pinyin，修改之后保存即可（压缩包内已经添加了修改之后的白名单，可以直接解压覆盖）。</p>
<p>3.到这里，我们所需要的一切准备工作已经做完了，可以开始安装拼音输入法了，同样，需要选择与自己机型相符的安装包，其中update_pinyin_0.4.2_*_install.bin是安装文件，update_pinyin_0.4.2_*_uninstall.bin是卸载文件，把匹配的安装包放在USB的根目录下，同样的方法进行Update，耐心的等待上一会儿，输入法就安装成功了。同样，卸载也是选择相匹配的卸载文件放置在根目录进行Update。</p>
<h2>关于升级：</h2>
<p>&nbsp; &nbsp;&nbsp; &nbsp; 之前安装过我发布的0.4/0.4.1版本拼音输入法的朋友可以直接使用update_pinyin_0.4.2_*_install.bin进行覆盖安装，而不需要先卸载（理论上可行，如果不放心可以先用老的uninstall文件卸载之）。</p>
<h2>使用方法：</h2>
<p>Sym：呼出输入法/关闭输入法；</p>
<p>Shift：切换中英文输入模式；</p>
<p>Shift+.：英文模式下输入半角特殊符号，中文模式下输入全角特殊符号；</p>
<p>空格：选择当前高亮的文字；</p>
<p>SELECT：选择当前高亮的文字；</p>
<p>←：向右移动焦点/向右移动光标；</p>
<p>→：向左移动焦点/向左移动光标；</p>
<p>↑：向上翻页/退出拼音编辑模式；</p>
<p>↓：向下翻页/进入拼音编辑模式；</p>
<p>Del：删除光标前的拼音；</p>
<p>输入数字：Shift切换为英文模式，按住Alt，再键入第一排Q-P，分别代表1、2、...、9、0（这是K3自带的输入方法）。</p>
<h2>附件在此：</h2>
<p><a title="最后下载:2026年03月20日,下载708次" href="http://terence2008.info/downloads/update_pinyin_0.4.2.zip">update_pinyin_0.4.2.zip</a></p>
<h2>截图：</h2>
<p><a href="http://terence2008.info/wp-content/uploads/2015/07/k3_pinyin_method.png" rel="lightbox[541]" title="k3_pinyin_method"><img class="alignnone size-medium wp-image-548" title="k3_pinyin_method" src="http://terence2008.info/wp-content/uploads/2015/07/k3_pinyin_method-225x300.png" alt="" width="225" height="300" /></a></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="[完美版发布！] Kindle 3 原生系统3.4.2拼音输入法完美版安装包[最新版本0.4.2]" href="http://terence2008.info/archives/kindle3_pinyin_input_method.html">《[完美版发布！] Kindle 3 原生系统3.4.2拼音输入法完美版安装包[最新版本0.4.2]》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/kindle3_cross_chaintool.html" title="分享自己做的Kindle3交叉编译工具链">分享自己做的Kindle3交叉编译工具链</a> (1)</li><li><a href="http://terence2008.info/archives/kindle3_launchpad.html" title="适用于Kindle 3 原生系统3.4.2 的Launchpad热键管理程序">适用于Kindle 3 原生系统3.4.2 的Launchpad热键管理程序</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/kindle3_pinyin_input_method.html/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>如何手动连接802.1x EAP证书加密WIFI</title>
		<link>http://terence2008.info/archives/how_to_connect_eap_wifi.html</link>
		<comments>http://terence2008.info/archives/how_to_connect_eap_wifi.html#comments</comments>
		<pubDate>Wed, 25 Feb 2015 09:40:54 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[网络技术]]></category>
		<category><![CDATA[WIFI]]></category>
		<category><![CDATA[证书]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=532</guid>
		<description><![CDATA[<p>首先声明一点：本文只是从实用角度来阐述如何免第三方工具连接通过802.1x EAP<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%af%81%e4%b9%a6" title="查看 证书 的全部文章">证书</a></span>加密的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/wifi" title="查看 WIFI 的全部文章">WIFI</a></span>，但并不以恶意地揣测第三方连接工具有多危险为目的。。。</p>
<h2>PRE START：为什么要这么做</h2>
<p>&nbsp; &nbsp; &nbsp; 其实我也不知道这么做的好处是啥，充其量也就是为了研究那些所谓的自动wifi连接工具的实际核心操作，二来也有想要一个相对纯净的系统的私心吧 <img src='https://terence2008.info/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> 。&nbsp;</p>
<h2>SETP 1：提取<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%af%81%e4%b9%a6" title="查看 证书 的全部文章">证书</a></span></h2>
<p>&nbsp; &nbsp; &nbsp; 这一步是关键，之所以网上基本上找不到手动方式连接通过802.1x EAP<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%af%81%e4%b9%a6" title="查看 证书 的全部文章">证书</a></span>加密的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/wifi" title="查看 WIFI 的全部文章">WIFI</a></span>是因为通常来讲，用第三方连接工具会帮你自动把所需要的证书导入到了你的系统中，但被标记为了不可导出私钥状态，因此你也没法获得到它。但通过Github大法一搜，还真被我搜到了一个项目，名叫jailbreak，通俗易懂，反正作用就是能够导出Windows下被标记为不可导出私钥的证书，这样一来最大的障碍就轻松扫除了，该项目从提交日志来看是近半年才开发出来的，所以在之前都是无法想像的事，不过有了这一工具后细细一想，越想越怕。。。是微软的漏洞么？</p>
<p>&nbsp; &nbsp; &nbsp; jailbreak用法也很简单，下载整个项目，复制jbcert.bat文件到binaries文件里，然后运行jbcert.bat，稍等片刻就会打开和运行“certmgr.msc”命令一样的界面，只不过这时候，所有被标记为不可导出私钥的证书都变成了浮云，快快导出成pfx文件吧。项目地址<a href="https://github.com/iSECPartners/jailbreak" target="_blank">点这里</a>。</p>
<p><a href="http://terence2008.info/wp-content/uploads/2015/02/certmgr.png" rel="lightbox[532]" title="certmgr"><img class="alignnone size-medium wp-image-533" title="certmgr" src="http://terence2008.info/wp-content/uploads/2015/02/certmgr-300x213.png" alt="" width="300" height="213" /></a></p>
<h2>SETP2：使用证书连接WIFI</h2>
<p>&nbsp; &nbsp; &nbsp; 这时候第三方连接工具已经没有了利用价值，可以果断卸载之。以下是Windows和Android两个系统的证书使用方式：</p>
<h3>Windows</h3>
<p>&nbsp; &nbsp; &nbsp; a.导入证书，双击pfx文件然后按向导提示导入。</p>
<p>&nbsp; &nbsp; &nbsp; b.创建连接点，打开网络和共享中心——管理无线网络（XP的童鞋自行脑补）——添加——手动创建网络配置文件，填写网络名（SSID），安全类型选WPA2-企业，然后下一步至完成。</p>
<p>&nbsp; &nbsp; &nbsp; c.设置连接点，右键属性刚刚创建的无线连接点，点安全，在选择网络身份验证方法选择“Microsoft：智能卡或其他证书”，然后确定。</p>
<p><a href="http://terence2008.info/wp-content/uploads/2015/02/setupssid.png" rel="lightbox[532]" title="setupssid"><img class="alignnone size-medium wp-image-534" title="setupssid" src="http://terence2008.info/wp-content/uploads/2015/02/setupssid-249x300.png" alt="" width="249" height="300" /></a></p>
<p>&nbsp; &nbsp; &nbsp; d.连接刚刚设置的无线点，会弹出证书选择对话框，选择导入的证书名，点确定，就连接上了，如果提示证书不受信任，就直接忽略继续连接。</p>
<p><a href="http://terence2008.info/wp-content/uploads/2015/02/connectwifi.png" rel="lightbox[532]" title="connectwifi"><img class="alignnone size-medium wp-image-535" title="connectwifi" src="http://terence2008.info/wp-content/uploads/2015/02/connectwifi-300x187.png" alt="" width="300" height="187" /></a></p>
<h3>Android</h3>
<p>&nbsp; &nbsp; &nbsp; a.导入证书，复制pfx文件到用户<strong>手机存储根目录</strong>下（/sdcard），<strong>更改后缀名为p12</strong>，然后进入设置——位置和安全——从USB存储器安装，输入完证书密码后就成功导入了。</p>
<p><a href="http://terence2008.info/wp-content/uploads/2015/02/andoird_1.png" rel="lightbox[532]" title="andoird_1"><img class="alignnone size-medium wp-image-536" title="andoird_1" src="http://terence2008.info/wp-content/uploads/2015/02/andoird_1-180x300.png" alt="" width="180" height="300" /></a></p>
<p><a href="http://terence2008.info/wp-content/uploads/2015/02/andoird_1.png"></a><a href="http://terence2008.info/wp-content/uploads/2015/02/andoird_2.png" rel="lightbox[532]" title="andoird_2"><img class="alignnone size-medium wp-image-537" title="andoird_2" src="http://terence2008.info/wp-content/uploads/2015/02/andoird_2-180x300.png" alt="" width="180" height="300" /></a></p>
<p>&nbsp; &nbsp; &nbsp; b.设置连接点，在WLAN设置里选择需要连接的802.1x EAP加密连接点，设置EAP方法为TLS，用户证书选择刚刚导入的证书，身份填写任意字符，<strong>但不能不填写</strong>。</p>
<p><a href="http://terence2008.info/wp-content/uploads/2015/02/andoird_3.png" rel="lightbox[532]" title="andoird_3"><img class="alignnone size-medium wp-image-539" title="andoird_3" src="http://terence2008.info/wp-content/uploads/2015/02/andoird_3-180x300.png" alt="" width="180" height="300" /></a></p>
<p>&nbsp; &nbsp; &nbsp; c.连接刚刚设置的无线点，点存储后应该很快就能连接上了。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="如何手动连接802.1x EAP证书加密WIFI" href="http://terence2008.info/archives/how_to_connect_eap_wifi.html">《如何手动连接802.1x EAP证书加密WIFI》</a></div></blockquote><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/001.html" title="写在最最开始">写在最最开始</a> (4)</li><li><a href="http://terence2008.info/archives/spring_in_jdk_classes_loding_bug.html" title="Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题">Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题</a> (1)</li><li><a href="http://terence2008.info/archives/change-space.html" title="换空间了">换空间了</a> (1)</li><li><a href="http://terence2008.info/archives/ssl_cdn_choose.html" title="关于SSL证书与CDN加速的选择">关于SSL证书与CDN加速的选择</a> (0)</li><li><a href="http://terence2008.info/archives/javamail_on_jdk8_ssl_problem.html" title="Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案">Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案</a> (0)</li><li><a href="http://terence2008.info/archives/008.html" title="信春哥 死后四次原地满血复活">信春哥 死后四次原地满血复活</a> (0)</li><li><a href="http://terence2008.info/archives/005.html" title="猜想2010年后的中国网络">猜想2010年后的中国网络</a> (0)</li><li><a href="http://terence2008.info/archives/backup-database-webroot.html" title="定时备份mysql和网站目录文件">定时备份mysql和网站目录文件</a> (0)</li><li><a href="http://terence2008.info/archives/006.html" title="电子杂志《物华特刊》发布！">电子杂志《物华特刊》发布！</a> (2)</li><li><a href="http://terence2008.info/archives/ubuntu_old_sources.html" title="老版本Ubuntu 11.04等的源列表">老版本Ubuntu 11.04等的源列表</a> (1)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/how_to_connect_eap_wifi.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>MyEclipse一站式调试Maven Web项目</title>
		<link>http://terence2008.info/archives/myeclipse_dubug_maven_project.html</link>
		<comments>http://terence2008.info/archives/myeclipse_dubug_maven_project.html#comments</comments>
		<pubDate>Sat, 13 Sep 2014 14:46:08 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[MyEclipse]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=526</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 之前使用Myeclipse开发完代码后，总是需要通过<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/maven" title="查看 Maven 的全部文章">Maven</a></span>程序打包成war包并拷贝到外部<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/tomcat" title="查看 Tomcat 的全部文章">Tomcat</a></span>的webapp目录下进行调试，Myeclipse去连接<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/tomcat" title="查看 Tomcat 的全部文章">Tomcat</a></span>的远程调试端口，感觉非常的麻烦。遂下决心一定要找到一个简便的，能在Myeclipse平台下一站式地开发和调试<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/maven" title="查看 Maven 的全部文章">Maven</a></span> Web项目。但网上对于Myeclipse一站式开发讲述的非常零散，在查阅了许多篇文章后，终于总结出了一个简单有效的方式，可以完全不用外部程序做到<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/svn" title="查看 svn 的全部文章">svn</a></span>代码检出、<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/maven" title="查看 Maven 的全部文章">Maven</a></span> Web项目支持以及通过Myeclipse内置的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/tomcat" title="查看 Tomcat 的全部文章">Tomcat</a></span>来调试项目。下面是详细的操作步骤：</p>
<h2>环境配置</h2>
<p>JDK 1.6</p>
<p>eclipse 3.6.2（有加载中文插件） + Myeclipse 9.1插件&nbsp;+ Subclipse 1.8.x插件（插件均以dropins方式加载）</p>
<p>Maven4MyEclipse + Myeclipse&nbsp;Integrated Sandbox&nbsp;Tomcat 6（Myeclipse 9.1均已内置）</p>
<h2>两点需要提醒的</h2>
<p>1、由于我使用了加载过中文插件的eclipse，部分界面是中文的，因此有些选项名称会和原版的不一样，但都可以找到对应的英文名称</p>
<p>2、在使用Maven4MyEclipse前，需要预先配置好settings.xml文件和指定Maven Local Repository目录，设置入口在窗口——首选项，依次点击Myeclipse——Maven4MyEclipse——Maven——User Settings</p>
<h2>SVN代码检出</h2>
<p>1、打开eclipse的“<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/svn" title="查看 svn 的全部文章">svn</a></span>资源库研究”透视图，添加<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/svn" title="查看 svn 的全部文章">svn</a></span>资源库</p>
<p>2、选中需要的分支目录然后右键——检出为，然后点完成</p>
<p>3、弹出的新建项目窗口选择常规——项目，然后点下一步，填写项目名后直接点完成</p>
<h2>开启Maven Web项目支持</h2>
<p>1、切换到“Myeclipse Java Enterprise”透视图，右键项目——运行方式——Maven Build</p>
<p>2、弹出的编辑配置窗口，在Goals输入框中输入“eclipse:eclipse”，点击运行</p>
<p>3、在看到控制台里显示Finished后，右键项目——刷新，此时eclipse已经可以正确加载Maven管理的Web项目了</p>
<p>4、右键项目——Myeclipse Maven——Enable Dependency Management，目的在于让Maven4MyEclipse接管Maven项目</p>
<p>5、如果开发需要还想下载jar包对应源码文件的话，右键项目——Myeclipse Maven——Download sources</p>
<h2>通过Myeclipse内置的Tomcat调试项目</h2>
<p>1、点击窗口——首选项，依次点击Myeclipse——Servers——Integrated Sandbox——Myeclipse Tomcat 6，点击右边的Enable，以及Restore Myeclipse Tomcat Server Installation，这一步很重要，很多Tomcat启动失败就是因为没有清空Tomcat运行目录导致的</p>
<p>2、如果需要修改Tomcat的JDK启动参数，可以在左边继续点到Myeclipse Tomcat 6——JDK，选择JDK name和添加Optional Java VM arguments，然后点击确定</p>
<p>3、右键项目——属性，选择Web Project Settings，把Context root修改为“/”，然后点确定</p>
<p>4、右键项目——调试方式——调试配置，右键左边的Myeclipse Server Application——新建</p>
<p>5、在右边修改下名称，然后选择对应的Project，Server选择Myeclipse Tomcat，取消选择Restart server to redeploy application，这样的好处是可以在修改完代码后立即生效（热代码替换），而不需要重启Tomcat，大大提高开发效率，最后点调试</p>
<p>6、如果第一次服务启动失败，可以先停止进程再重试一次，右键项目——调试方式——Myeclipse Server Application</p>
<p>&nbsp;</p>
<p>&nbsp; &nbsp; &nbsp; 至此，全部配置完毕，以后就可以用Myeclipse进行一站式开发、部署和调试操作了。在看到控制台里显示“Server startup in xxx ms”就意味着服务已经启动成功，访问http://localhost:8080/就能看到网页了。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="MyEclipse一站式调试Maven Web项目" href="http://terence2008.info/archives/myeclipse_dubug_maven_project.html">《MyEclipse一站式调试Maven Web项目》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/eclipse-optimizing.html" title="Eclipse性能优化实践">Eclipse性能优化实践</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/myeclipse_dubug_maven_project.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress数据库的一处性能优化</title>
		<link>http://terence2008.info/archives/wordpress_database_optimize.html</link>
		<comments>http://terence2008.info/archives/wordpress_database_optimize.html#comments</comments>
		<pubDate>Tue, 22 Jul 2014 15:13:46 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[性能优化]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=524</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 前几天发现博客的响应速度略有降低，除了经常被并发攻击所导致的线程等待原因外，隐隐觉得是不是在数据库方面还有提升的空间。因此打开了MySQL慢查询日志记录开关，记录查询超过1秒的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/sql" title="查看 SQL 的全部文章">SQL</a></span>语句。经过一周的运行，当我再次打开慢查询日志文件时，终于有所发现，以下是日志文件的去重后部分：</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #66cc66;">/</span>usr<span style="color: #66cc66;">/</span>libexec<span style="color: #66cc66;">/</span>mysqld<span style="color: #66cc66;">,</span> Version: 5<span style="color: #66cc66;">.</span>1<span style="color: #66cc66;">.</span>73<span style="color: #66cc66;">-</span>log <span style="color: #66cc66;">&#40;</span>Source distribution<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">.</span> started <span style="color: #993333; font-weight: bold;">WITH</span>:
Tcp port: <span style="color: #cc66cc;">4000</span>  Unix socket: <span style="color: #66cc66;">/</span>var<span style="color: #66cc66;">/</span>lib<span style="color: #66cc66;">/</span>mysql<span style="color: #66cc66;">/</span>mysql<span style="color: #66cc66;">.</span>sock
Time                 Id Command    Argument
<span style="color: #808080; font-style: italic;"># Time: 140720  5:00:55</span>
<span style="color: #808080; font-style: italic;"># User@Host: twx[twx] @ localhost []</span>
<span style="color: #808080; font-style: italic;"># Query_time: 1.421887  Lock_time: 0.026132 Rows_sent: 232  Rows_examined: 279</span>
<span style="color: #993333; font-weight: bold;">USE</span> wordpress;
<span style="color: #993333; font-weight: bold;">SET</span> timestamp<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1405803655</span>;
<span style="color: #993333; font-weight: bold;">SELECT</span> option_name<span style="color: #66cc66;">,</span> option_value <span style="color: #993333; font-weight: bold;">FROM</span> wp_options <span style="color: #993333; font-weight: bold;">WHERE</span> autoload <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'yes'</span>;</pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 可以看到，SELECT option_name, option_value FROM wp_options WHERE autoload = 'yes' 这条语句在日志中大量存在，而且查询时间都是在1.5秒左右，这是不能忍受的，因此需要查看执行计划，分析这条语句为什么会这么慢。MySQL的explain语句可以帮助我分析原因：</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">EXPLAIN</span> <span style="color: #993333; font-weight: bold;">SELECT</span> option_name<span style="color: #66cc66;">,</span> option_value <span style="color: #993333; font-weight: bold;">FROM</span> wp_options <span style="color: #993333; font-weight: bold;">WHERE</span> autoload <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'yes'</span>;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----+-------------+------------+------+---------------+------+---------+------+------+-------------+</span>
<span style="color: #66cc66;">|</span> id <span style="color: #66cc66;">|</span> select_type <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">TABLE</span>      <span style="color: #66cc66;">|</span> type <span style="color: #66cc66;">|</span> possible_keys <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">KEY</span>  <span style="color: #66cc66;">|</span> key_len <span style="color: #66cc66;">|</span> ref  <span style="color: #66cc66;">|</span> rows <span style="color: #66cc66;">|</span> Extra       <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----+-------------+------------+------+---------------+------+---------+------+------+-------------+</span>
<span style="color: #66cc66;">|</span>  <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">|</span> SIMPLE      <span style="color: #66cc66;">|</span> wp_options <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">ALL</span>  <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>          <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span>    <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">|</span>  <span style="color: #cc66cc;">206</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">USING</span> <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----+-------------+------------+------+---------------+------+---------+------+------+-------------+</span>
<span style="color: #cc66cc;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 这里需要解释下执行计划中各个项目的代表含义：</p>
<p>table：显示这一行的数据是关于哪张表的</p>
<p>type：这是重要的列，显示连接使用了何种类型。从最好到最差的连接类型为const、eq_reg、ref、range、indexhe和ALL</p>
<p>possible_keys：显示可能应用在这张表中的索引。如果为空，没有可能的索引。可以为相关的域从WHERE语句中选择一个合适的语句</p>
<p>key：实际使用的索引。如果为NULL，则没有使用索引。很少的情况下，MySQL会选择优化不足的索引。这种情况下，可以在SELECT语句中使用USE INDEX（indexname）来强制使用一个索引或者用IGNORE INDEX（indexname）来强制MySQL忽略索引</p>
<p>key_len：使用的索引的长度。在不损失精确性的情况下，长度越短越好</p>
<p>ref：显示索引的哪一列被使用了，如果可能的话，是一个常数</p>
<p>rows：MySQL认为必须检查的用来返回请求数据的行数</p>
<p>Extra：关于MySQL如何解析查询的额外信息，将在下面讨论，比较坏的情况是Using temporary和Using filesort，意思MySQL根本不能使用索引，结果是检索会很慢</p>
<p><strong>extra列返回的描述意义：</strong></p>
<p>Distinct：一旦MySQL找到了与行相联合匹配的行，就不再搜索了</p>
<p>Not exists：MySQL优化了LEFT JOIN，一旦它找到了匹配LEFT JOIN标准的行，就不再搜索了</p>
<p>Range checked for each Record（index map:#）：没有找到理想的索引，因此对于从前面表中来的每一个行组合，MySQL检查使用哪个索引，并用它来从表中返回行。这是使用索引的最慢的连接之一</p>
<p>Using filesort：看到这个的时候，查询就需要优化了。MySQL需要进行额外的步骤来发现如何对返回的行排序。它根据连接类型以及存储排序键值和匹配条件的全部行的行指针来排序全部行</p>
<p>Using index：列数据是从仅仅使用了索引中的信息而没有读取实际的行动的表返回的，这发生在对表的全部的请求列都是同一个索引的部分的时候</p>
<p>Using temporary：看到这个的时候，查询需要优化了。这里，MySQL需要创建一个临时表来存储结果，这通常发生在对不同的列集进行ORDER BY上，而不是GROUP BY上</p>
<p>Where used：使用了WHERE从句来限制哪些行将与下一张表匹配或者是返回给用户。如果不想返回表中的全部行，并且连接类型ALL或index，这就会发生，或者是查询有问题不同连接类型的解释（按照效率高低的顺序排序）</p>
<p>system：表只有一行，system表。这是const连接类型的特殊情况</p>
<p>const：表中的一个记录的最大值能够匹配这个查询（索引可以是主键或惟一索引）。因为只有一行，这个值实际就是常数，因为MYSQL先读这个值然后把它当做常数来对待</p>
<p>eq_ref：在连接中，MySQL在查询时，从前面的表中，对每一个记录的联合都从表中读取一个记录，它在查询使用了索引为主键或惟一键的全部时使用</p>
<p>ref：这个连接类型只有在查询使用了不是惟一或主键的键或者是这些类型的部分（比如，利用最左边前缀）时发生。对于之前的表的每一个行联合，全部记录都将从表中读出。这个类型严重依赖于根据索引匹配的记录多少—越少越好</p>
<p>range：这个连接类型使用索引返回一个范围中的行，比如使用&gt;或&lt;查找东西时发生的情况</p>
<p>index：这个连接类型对前面的表中的每一个记录联合进行完全扫描（比ALL更好，因为索引一般小于表数据）</p>
<p>ALL：这个连接类型对于前面的每一个记录联合进行完全扫描，这一般比较糟糕，应该尽量避免</p>
<p>&nbsp;</p>
<p>&nbsp; &nbsp; &nbsp; 科普完执行计划后，上面的例子就能很清晰的看到这条<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/sql" title="查看 SQL 的全部文章">SQL</a></span>查询没有使用到索引，进入到wp_options表结构查看索引情况，果然没有把autoload列加入到索引中，所以解决方法很简单，只要把autoload列添加索引就能解决了，语句如下：</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">ALTER</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`wp_options`</span> <span style="color: #993333; font-weight: bold;">ADD</span> <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #ff0000;">`autoload`</span> <span style="color: #993333; font-weight: bold;">USING</span> BTREE <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`autoload`</span><span style="color: #66cc66;">&#41;</span> ;</pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 我们再来看下这条SQL语句的执行计划：</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">mysql<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">EXPLAIN</span> <span style="color: #993333; font-weight: bold;">SELECT</span> option_name<span style="color: #66cc66;">,</span> option_value <span style="color: #993333; font-weight: bold;">FROM</span> wp_options <span style="color: #993333; font-weight: bold;">WHERE</span> autoload <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'yes'</span>;
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----+-------------+------------+------+---------------+----------+---------+-------+------+-------------+</span>
<span style="color: #66cc66;">|</span> id <span style="color: #66cc66;">|</span> select_type <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">TABLE</span>      <span style="color: #66cc66;">|</span> type <span style="color: #66cc66;">|</span> possible_keys <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">KEY</span>      <span style="color: #66cc66;">|</span> key_len <span style="color: #66cc66;">|</span> ref   <span style="color: #66cc66;">|</span> rows <span style="color: #66cc66;">|</span> Extra       <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----+-------------+------------+------+---------------+----------+---------+-------+------+-------------+</span>
<span style="color: #66cc66;">|</span>  <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">|</span> SIMPLE      <span style="color: #66cc66;">|</span> wp_options <span style="color: #66cc66;">|</span> ref  <span style="color: #66cc66;">|</span> autoload      <span style="color: #66cc66;">|</span> autoload <span style="color: #66cc66;">|</span> <span style="color: #cc66cc;">62</span>      <span style="color: #66cc66;">|</span> const <span style="color: #66cc66;">|</span>  <span style="color: #cc66cc;">119</span> <span style="color: #66cc66;">|</span> <span style="color: #993333; font-weight: bold;">USING</span> <span style="color: #993333; font-weight: bold;">WHERE</span> <span style="color: #66cc66;">|</span>
<span style="color: #66cc66;">+</span><span style="color: #808080; font-style: italic;">----+-------------+------------+------+---------------+----------+---------+-------+------+-------------+</span>
<span style="color: #cc66cc;">1</span> row <span style="color: #993333; font-weight: bold;">IN</span> <span style="color: #993333; font-weight: bold;">SET</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 至此，<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96" title="查看 性能优化 的全部文章">性能优化</a></span>完成，虽然还不知道<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/wordpress" title="查看 WordPress 的全部文章">WordPress</a></span>在什么情况下会执行此条语句，但可以确定的是在其最新版本上也是没有添加该索引的，接下来我会继续观察慢查询日志中的反馈情况。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="WordPress数据库的一处性能优化" href="http://terence2008.info/archives/wordpress_database_optimize.html">《WordPress数据库的一处性能优化》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/blog_maintenance.html" title="博客维护日记">博客维护日记</a> (0)</li><li><a href="http://terence2008.info/archives/qqgroup_data_miner.html" title="对QQ群关系数据库的数据挖掘">对QQ群关系数据库的数据挖掘</a> (17)</li><li><a href="http://terence2008.info/archives/eclipse-optimizing.html" title="Eclipse性能优化实践">Eclipse性能优化实践</a> (0)</li><li><a href="http://terence2008.info/archives/tinymce-firefox.html" title="TinyMCE编辑器对FireFox的兼容不太好">TinyMCE编辑器对FireFox的兼容不太好</a> (1)</li><li><a href="http://terence2008.info/archives/my-plugins.html" title="我正在使用的插件列表">我正在使用的插件列表</a> (1)</li><li><a href="http://terence2008.info/archives/change-space.html" title="换空间了">换空间了</a> (1)</li><li><a href="http://terence2008.info/archives/013.html" title="Google阅读器里RSS的显示问题">Google阅读器里RSS的显示问题</a> (0)</li><li><a href="http://terence2008.info/archives/010.html" title="网页中连续字符手动换行的方法">网页中连续字符手动换行的方法</a> (0)</li><li><a href="http://terence2008.info/archives/009.html" title="让flash植入代码符合xhtml标准">让flash植入代码符合xhtml标准</a> (1)</li><li><a href="http://terence2008.info/archives/001.html" title="写在最最开始">写在最最开始</a> (4)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/wordpress_database_optimize.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题</title>
		<link>http://terence2008.info/archives/spring_in_jdk_classes_loding_bug.html</link>
		<comments>http://terence2008.info/archives/spring_in_jdk_classes_loding_bug.html#comments</comments>
		<pubDate>Sat, 31 May 2014 11:48:26 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JVM]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=519</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 一次偶然的机会，为了测试公司项目新代码需要，把svn上的代码检出到了一台新的测试机器上，机器上的环境都是自己通过yum安装的，本文发生的原因也是因此而起。</p>
<p>&nbsp; &nbsp; &nbsp; 在测试的过程中我点了一个链接，地址是http://10.69.67.203/exception/list/1&nbsp;，结果抛出了匪夷所思的500错误，报错内容如下（项目采用的是<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/spring" title="查看 Spring 的全部文章">Spring</a></span> MVC+Hibernate+Velocity架构）：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">AssertionFailure</span><span style="color: #339933;">:</span> Interceptor.<span style="color: #006633;">onPrepareStatement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> returned <span style="color: #000066; font-weight: bold;">null</span> or empty string.
	<span style="color: #006633;">at</span> org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">jdbc</span>.<span style="color: #006633;">AbstractBatcher</span>.<span style="color: #006633;">getSQL</span><span style="color: #009900;">&#40;</span>AbstractBatcher.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">490</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">jdbc</span>.<span style="color: #006633;">AbstractBatcher</span>.<span style="color: #006633;">getPreparedStatement</span><span style="color: #009900;">&#40;</span>AbstractBatcher.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">510</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">jdbc</span>.<span style="color: #006633;">AbstractBatcher</span>.<span style="color: #006633;">getPreparedStatement</span><span style="color: #009900;">&#40;</span>AbstractBatcher.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">452</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">jdbc</span>.<span style="color: #006633;">AbstractBatcher</span>.<span style="color: #006633;">prepareQueryStatement</span><span style="color: #009900;">&#40;</span>AbstractBatcher.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">161</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">loader</span>.<span style="color: #006633;">Loader</span>.<span style="color: #006633;">prepareQueryStatement</span><span style="color: #009900;">&#40;</span>Loader.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1700</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">loader</span>.<span style="color: #006633;">Loader</span>.<span style="color: #006633;">doQuery</span><span style="color: #009900;">&#40;</span>Loader.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">801</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">loader</span>.<span style="color: #006633;">Loader</span>.<span style="color: #006633;">doQueryAndInitializeNonLazyCollections</span><span style="color: #009900;">&#40;</span>Loader.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">274</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">loader</span>.<span style="color: #006633;">Loader</span>.<span style="color: #006633;">doList</span><span style="color: #009900;">&#40;</span>Loader.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">2542</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">loader</span>.<span style="color: #006633;">Loader</span>.<span style="color: #006633;">listIgnoreQueryCache</span><span style="color: #009900;">&#40;</span>Loader.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">2276</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">loader</span>.<span style="color: #006633;">Loader</span>.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span>Loader.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">2271</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">loader</span>.<span style="color: #006633;">custom</span>.<span style="color: #006633;">CustomLoader</span>.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span>CustomLoader.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">316</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">impl</span>.<span style="color: #006633;">SessionImpl</span>.<span style="color: #006633;">listCustomQuery</span><span style="color: #009900;">&#40;</span>SessionImpl.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">1842</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">impl</span>.<span style="color: #006633;">AbstractSessionImpl</span>.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span>AbstractSessionImpl.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">165</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">impl</span>.<span style="color: #006633;">SQLQueryImpl</span>.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span>SQLQueryImpl.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">157</span><span style="color: #009900;">&#41;</span>
	at org.<span style="color: #006633;">hibernate</span>.<span style="color: #006633;">impl</span>.<span style="color: #006633;">AbstractQueryImpl</span>.<span style="color: #006633;">uniqueResult</span><span style="color: #009900;">&#40;</span>AbstractQueryImpl.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">890</span><span style="color: #009900;">&#41;</span>
	at com.<span style="color: #006633;">yun</span>.<span style="color: #006633;">dba</span>.<span style="color: #006633;">exception</span>.<span style="color: #006633;">dao</span>.<span style="color: #006633;">ExceptionDaoImpl</span>.<span style="color: #006633;">countExceptionInfoByCondition</span><span style="color: #009900;">&#40;</span>ExceptionDaoImpl.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">83</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 大致看了下报错原因，猜测应该是Hibernate在执行SQL查询时提交了一个空字符串导致了执行失败，这个异常就显得比较诡异了，毕竟线上环境运行的也是同一套代码，不可能是代码问题，而且将代码部署在本机上运行也是好好的。没法，只得开放jvm远程调试端口进行代码步进跟踪，结果不出所料地跟到了Dao层，果然是SQL拼接语句为空，然后继续跟进，贴出相关代码：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>ExceptionInfo<span style="color: #339933;">&gt;</span> getExceptionInfoByCondition<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>SearchSupport<span style="color: #339933;">&gt;</span> searchList,
                            <span style="color: #003399;">Integer</span> targetType, <span style="color: #003399;">Integer</span> pageNo,
                            <span style="color: #003399;">Integer</span> pageSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    ......
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>targetType <span style="color: #339933;">==</span> TARGET_TYPE_CUSTINS <span style="color: #339933;">||</span> targetType <span style="color: #339933;">==</span> TARGET_TYPE_SPACE
            <span style="color: #339933;">||</span> targetType <span style="color: #339933;">==</span> TARGET_TYPE_DNS<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        lastSql <span style="color: #339933;">+=</span> <span style="color: #0000ff;">&quot; and ci.is_deleted=0 order by excp.gmt_created desc &quot;</span><span style="color: #339933;">;</span>
        sql <span style="color: #339933;">=</span> makeSearchListToSql<span style="color: #009900;">&#40;</span>searchList, GET_CUSTINS_BY_CONDITION, lastSql, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>targetType <span style="color: #339933;">==</span> TARGET_TYPE_HOST<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        lastSql <span style="color: #339933;">+=</span> <span style="color: #0000ff;">&quot; order by excp.gmt_created desc &quot;</span><span style="color: #339933;">;</span>
        sql <span style="color: #339933;">=</span> makeSearchListToSql<span style="color: #009900;">&#40;</span>searchList, GET_HOST_BY_CONDITION, lastSql, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    ......
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 此时，targetType传入的值是1，理应进入到else if这个判断里，其中TARGET_TYPE_HOST的定义是“public final static Integer TARGET_TYPE_HOST = 1”。但神奇的是它根本没有跳入判断里。也许看到这里你会说Integer是一个对象，应该使用equals()方法进行数值比较，没错，但<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/java" title="查看 Java 的全部文章">Java</a></span>从5.0起就有一种自动装箱、拆箱的机制，下面就大概介绍下这种特性：</p>
<p>&nbsp; &nbsp; &nbsp; 装箱：把基本类型用它们相应的引用类型包装起来，使其具有对象的性质。int包装成Integer、float包装成Float；拆箱：和装箱相反，将引用类型的对象简化成值类型的数据。</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Integer</span> a1 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>           <span style="color: #666666; font-style: italic;">//这是自动装箱  (编译器调用的是static Integer valueOf(int i))</span>
<span style="color: #003399;">Integer</span> a2 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> b <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Integer</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>   <span style="color: #666666; font-style: italic;">//这是自动拆箱</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 上面的例子中a1和a2如果用==运算符进行判断的话，其返回值为true，因为a1和a2代表的是同一个对象，我们可以看下valueOf()的具体实现：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Integer</span> valueOf<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> offset <span style="color: #339933;">=</span> <span style="color: #cc66cc;">128</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">&gt;=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">128</span> <span style="color: #339933;">&amp;&amp;</span> i <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">127</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// must cache</span>
        <span style="color: #000000; font-weight: bold;">return</span> IntegerCache.<span style="color: #006633;">cache</span><span style="color: #009900;">&#91;</span>i <span style="color: #339933;">+</span> offset<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Integer</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 很明显，jvm定义了在[-128，127]之间的数字，valueOf返回的是缓存中的对象，所以两次调用返回的是同一个对象，所以所有在这个范围内的值相等的Integer对象都会共用一块内存，而不会开辟多个，超出这个范围内的值对应的Integer对象有多少个就开辟多少个内存。说白了，这是一种语法糖。所以再来看出错的代码，理应就属于我们提到的a1==a2这种情况，可为什么还是判断为不属于同一个对象呢？没办法，我们只能再跟踪上层的代码，所以来到了Control层：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@RequestMapping<span style="color: #009900;">&#40;</span>value <span style="color: #339933;">=</span> UrlPatternConsts.<span style="color: #006633;">EXCEPTION_LIST</span>, method <span style="color: #339933;">=</span> RequestMethod.<span style="color: #006633;">GET</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> ModelAndView instancelist<span style="color: #009900;">&#40;</span>HttpServletRequest request, ModelAndView mav,
                                 @PathVariable <span style="color: #003399;">Integer</span> targetType<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">Integer</span> page <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    innerInstanceList<span style="color: #009900;">&#40;</span>mav, page, targetType<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">return</span> mav<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; Dao层中的targetType就是来自于这里，targetType这个对象是通过Http请求，利用<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/spring" title="查看 Spring 的全部文章">Spring</a></span>的@PathVariable注解而来，这里会有一个反射机制。到这里事情开始变的有些眉目起来。反射机制指的是程序在运行时能够获取自身的信息，只要给定类的名字，那么就可以通过反射机制来获得类的所有信息。反射机制的优点就是可以实现动态创建对象和编译，体现出很大的灵活性，特别是在J2EE的开发中它的灵活性就表现的十分明显。正因为反射机制会有动态类装载的行为，因此我有理由怀疑是不是因为jvm在类的装载顺序上面有问题才会导致注解而得的Integer对象不同于自动装箱而得的同值Integer对象。因此我增加了几行测试代码来验证我的判断：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@RequestMapping<span style="color: #009900;">&#40;</span>value <span style="color: #339933;">=</span> UrlPatternConsts.<span style="color: #006633;">EXCEPTION_LIST</span>, method <span style="color: #339933;">=</span> RequestMethod.<span style="color: #006633;">GET</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> ModelAndView instancelist<span style="color: #009900;">&#40;</span>HttpServletRequest request, ModelAndView mav,
                             @PathVariable <span style="color: #003399;">Integer</span> targetType<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003399;">Integer</span> page <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Integer</span> test<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;test<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>targetType<span style="color: #339933;">==</span>test<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>page<span style="color: #339933;">==</span>test<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;end test<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    innerInstanceList<span style="color: #009900;">&#40;</span>mav, page, targetType<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">return</span> mav<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 将上面的改动应用在了测试机器上，发送了Http请求后在控制台打印出来了结果：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">test
false
true
end test</pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 果然targetType和test是不等于的，同样地，我把代码又应用在了本机，打印的结果又是这样的：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">test
true
true
end test</pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 问题终于显现！注解反射生成后的Integer对象与自动装包生成的同值对象在不同的机器上会出现两种截然不同的表现，那接下来就是查看各自的jvm版本了，在本机的jvm版本如下：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">java version &quot;1.6.0_45&quot;
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)</pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 测试机器的jvm版本如下：</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">java version &quot;1.6.0_30&quot;
OpenJDK Runtime Environment (IcedTea6 1.13.1) (rhel-3.1.13.1.el6_5-x86_64)
OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)</pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 结果很明显，CentOS下采用yum安装的是OpenJDK的jvm，在它运行的Sping容器内，注解反射后的Integer装载类与自动装箱的Integer装载类不属于同一个内存区域，而Oracle的jvm却属于同一个内存区域，Oracle的做法更贴合于<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/java" title="查看 Java 的全部文章">Java</a></span>想要表达的语法糖这个特性，而OpenJDK的做法我更倾向于是一个类装载bug。最终的处理方式就是卸载测试机上的OpenJDK改用Oracle JDK后，500报错现象解除。</p>
<p>&nbsp; &nbsp; &nbsp; 最后总结一下，为了调试这个错误，花了我半天的时间才找到原因，究其根本就是太过依赖于Java带给我们的语法糖特性，有时候在不知道原理的情况下任意使用，很可能会碰到一些坑。保险的用法就是在遇到任何对象的等值比较时，使用equals()方法是最最稳妥的。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题" href="http://terence2008.info/archives/spring_in_jdk_classes_loding_bug.html">《Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/javamail_on_jdk8_ssl_problem.html" title="Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案">Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案</a> (0)</li><li><a href="http://terence2008.info/archives/ajaxswing.html" title="AjaxSwing4.4.0授权码">AjaxSwing4.4.0授权码</a> (2)</li><li><a href="http://terence2008.info/archives/hibernate_criteria_order.html" title="Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作">Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作</a> (2)</li><li><a href="http://terence2008.info/archives/eclipse-optimizing.html" title="Eclipse性能优化实践">Eclipse性能优化实践</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/spring_in_jdk_classes_loding_bug.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>VAMT 3.1独立版下载</title>
		<link>http://terence2008.info/archives/vamt_3_1_independent_version.html</link>
		<comments>http://terence2008.info/archives/vamt_3_1_independent_version.html#comments</comments>
		<pubDate>Tue, 27 May 2014 09:06:05 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[微软]]></category>
		<category><![CDATA[激活]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=516</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 玩过<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e5%be%ae%e8%bd%af" title="查看 微软 的全部文章">微软</a></span>MAK key的同学一定知道VAMT这个工具吧，它的全称是Volume Activation Management Tool，本意是<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e5%be%ae%e8%bd%af" title="查看 微软 的全部文章">微软</a></span>专门为企业开发的批量<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%bf%80%e6%b4%bb" title="查看 激活 的全部文章">激活</a></span>管理工具，现在主要用来个人检测<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e5%be%ae%e8%bd%af" title="查看 微软 的全部文章">微软</a></span>密钥的可用性和<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%bf%80%e6%b4%bb" title="查看 激活 的全部文章">激活</a></span>次数，包括的产品有Office套件系列、Windows系列等。需要注意的是MAK key只能用来<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%bf%80%e6%b4%bb" title="查看 激活 的全部文章">激活</a></span>标有vol的微软产品，而对rtm产品无效，其实实际上vol和rtm仅仅是软件授权方式上有区别，在功能和版本上没有任何的区别。</p>
<p>&nbsp; &nbsp; &nbsp; 老的VAMT版本不能检测新的微软产品密钥，例如，VAMT 2.0最多能支持到Office 2010和Windows 7，VAMT 3.0最多能支持到Office 2013和Windows 8，而VAMT 3.1则能支持到Windows 8.1以及Windows Server 2012 R2。当然高版本的VAMT能够向下兼容老版本的微软产品密钥。</p>
<p>&nbsp; &nbsp; &nbsp; 但抓狂的是自VAMT 3.0起，它的安装包就不再是一个独立的版本了，取而代之的是被整合在了Windows ADK中，必须从官网下载adksetup.exe，然后进行联网安装。引导程序虽小，但下载组件却需要约240M的数据，所花时间较长，若网络不好或恰好赶上网络繁忙，那需要的时间就很长很长了。</p>
<p>&nbsp; &nbsp; &nbsp; 通过对安装包的分析，我终于从Windows ADK中提炼出了独立的VAMT 3.1安装包，压缩完后只有1.3M，非常迷你吧。但安装VAMT 3.1不是那么容易的，因为它需要.NET Framework 4.5的支持，但如果你经常使用Windows Update的话我相信.net 4.5十有八九是安装过的，所以问题不大。</p>
<p>&nbsp; &nbsp; &nbsp; 但最大的麻烦是VAMT 3.1需要SQL Server的支持，这里有两种解决方案：一种是在本地下载安装SQL Server 2008 Express以上的版本，安装成功后直接打开VAMT登陆本机数据库服务器地址就可以自动创建新数据库了；另一种方案就比较麻烦了，主要供不想在本机安装SQL Server的同学参考，由于VAMT的数据库登陆方式只支持Windows 用户验证登陆方式，因此如果要采用非本机的SQL Server，就必须做到本机的Windows登陆账户名和密码与SQL Server服务器上的Windows登陆账户是完全一致的，例如本机采用Administrator/123456的账户，SQL Server服务器上也必须存在Administrator/123456这个账户，其次就是在SQL Server服务器上授予该Windows账户一个sysadmin的角色权限。</p>
<p>&nbsp; &nbsp; &nbsp; 当VAMT连接成功了SQL Server后，接下来的就可以验证各种密钥了。在文章最后附上我的VAMT 3.1独立版下载地址，另外需要注意的是VAMT 3.1不支持在Windows XP上安装：</p>
<p><a title="最后下载:2026年03月17日,下载1183次" href="http://terence2008.info/downloads/VAMT_3_1.7z">VAMT_3_1.7z</a></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="VAMT 3.1独立版下载" href="http://terence2008.info/archives/vamt_3_1_independent_version.html">《VAMT 3.1独立版下载》</a></div></blockquote><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/javamail_on_jdk8_ssl_problem.html" title="Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案">Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案</a> (0)</li><li><a href="http://terence2008.info/archives/android-iphone-girl.html" title="智能手机的另一大功能——造星">智能手机的另一大功能——造星</a> (2)</li><li><a href="http://terence2008.info/archives/i-expect.html" title="我期待……">我期待……</a> (2)</li><li><a href="http://terence2008.info/archives/ubuntu-service-autostart.html" title="Ubuntu的两种服务自启动模式">Ubuntu的两种服务自启动模式</a> (0)</li><li><a href="http://terence2008.info/archives/google-adsense.html" title="巧用Google AdSense赚美元">巧用Google AdSense赚美元</a> (1)</li><li><a href="http://terence2008.info/archives/unicode_encoding_conversion.html" title="Unicode编码在线转换工具">Unicode编码在线转换工具</a> (0)</li><li><a href="http://terence2008.info/archives/003.html" title="推荐一个博客">推荐一个博客</a> (0)</li><li><a href="http://terence2008.info/archives/myeclipse_dubug_maven_project.html" title="MyEclipse一站式调试Maven Web项目">MyEclipse一站式调试Maven Web项目</a> (0)</li><li><a href="http://terence2008.info/archives/007.html" title="李献计历险记">李献计历险记</a> (1)</li><li><a href="http://terence2008.info/archives/005.html" title="猜想2010年后的中国网络">猜想2010年后的中国网络</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/vamt_3_1_independent_version.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Chrome进行大小写字符敏感的内容查找</title>
		<link>http://terence2008.info/archives/chrome_case_sensitive_search.html</link>
		<comments>http://terence2008.info/archives/chrome_case_sensitive_search.html#comments</comments>
		<pubDate>Mon, 07 Apr 2014 16:44:12 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[Chrome]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=512</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 用过<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/chrome" title="查看 Chrome 的全部文章">Chrome</a></span>内容查找功能的人都知道在搜索英文字符串的时候它是不区分大小写的，这对于经常检索代码关键字的人来说这是非常不方便的。比如搜索“Hello”的时候会把“hello”等相关无用的字符串都给标记高亮了。</p>
<p>&nbsp; &nbsp; &nbsp; 当然解决方法是有，就是会麻烦些，我们通过自定义js书签的方式变相实现了该功能。首先新建一个书签，名称随便写，网址栏填入以下js代码：</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">javascript<span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">var</span> text<span style="color: #339933;">=</span><span style="color: #000066;">prompt</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Search for:'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>if<span style="color: #009900;">&#40;</span>text<span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">||</span> text.<span style="color: #660066;">length</span><span style="color: #339933;">==</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>var spans<span style="color: #339933;">=</span>document.<span style="color: #660066;">getElementsByClassName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'labnol'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>if<span style="color: #009900;">&#40;</span>spans<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>i <span style="color: #339933;">&lt;</span> spans.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>spans<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">style</span>.<span style="color: #660066;">backgroundColor</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'transparent'</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #003366; font-weight: bold;">function</span> searchWithinNode<span style="color: #009900;">&#40;</span>node<span style="color: #339933;">,</span>te<span style="color: #339933;">,</span>len<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #003366; font-weight: bold;">var</span> pos<span style="color: #339933;">,</span>skip<span style="color: #339933;">,</span>spannode<span style="color: #339933;">,</span>middlebit<span style="color: #339933;">,</span>endbit<span style="color: #339933;">,</span>middleclone<span style="color: #339933;">;</span>skip<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>if<span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">nodeType</span><span style="color: #339933;">==</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>pos<span style="color: #339933;">=</span>node.<span style="color: #660066;">data</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span>te<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>if<span style="color: #009900;">&#40;</span>pos<span style="color: #339933;">&gt;=</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>spannode<span style="color: #339933;">=</span>document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'span'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>spannode.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'labnol'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>spannode.<span style="color: #660066;">style</span>.<span style="color: #660066;">backgroundColor</span><span style="color: #339933;">=</span><span style="color: #3366CC;">'yellow'</span><span style="color: #339933;">;</span>middlebit<span style="color: #339933;">=</span>node.<span style="color: #660066;">splitText</span><span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>endbit<span style="color: #339933;">=</span>middlebit.<span style="color: #660066;">splitText</span><span style="color: #009900;">&#40;</span>len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>middleclone<span style="color: #339933;">=</span>middlebit.<span style="color: #660066;">cloneNode</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>spannode.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>middleclone<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>middlebit.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">replaceChild</span><span style="color: #009900;">&#40;</span>spannode<span style="color: #339933;">,</span>middlebit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>skip<span style="color: #339933;">=</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">nodeType</span><span style="color: #339933;">==</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">&amp;&amp;</span> node.<span style="color: #660066;">childNodes</span> <span style="color: #339933;">&amp;&amp;</span> node.<span style="color: #660066;">tagName</span>.<span style="color: #660066;">toUpperCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #3366CC;">'SCRIPT'</span> <span style="color: #339933;">&amp;&amp;</span> node.<span style="color: #660066;">tagName</span>.<span style="color: #660066;">toUpperCase</span> <span style="color: #339933;">!=</span><span style="color: #3366CC;">'STYLE'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> child<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>child <span style="color: #339933;">&lt;</span> node.<span style="color: #660066;">childNodes</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;++</span>child<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>child<span style="color: #339933;">=</span>child<span style="color: #339933;">+</span>searchWithinNode<span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">childNodes</span><span style="color: #009900;">&#91;</span>child<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>te<span style="color: #339933;">,</span>len<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">return</span> skip<span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>searchWithinNode<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">body</span><span style="color: #339933;">,</span>text<span style="color: #339933;">,</span>text.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 可以把该书签放在<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/chrome" title="查看 Chrome 的全部文章">Chrome</a></span>书签栏上，方便调用。使用的时候就比较简单了，点击下该书签，会弹出个输入框，试试输入字符串，然后确定，有没有发现页面里高亮出来的是大小写完全匹配的字符串啦？ <img src='https://terence2008.info/wp-includes/images/smilies/icon_cool.gif' alt='8-)' class='wp-smiley' /> </p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="Chrome进行大小写字符敏感的内容查找" href="http://terence2008.info/archives/chrome_case_sensitive_search.html">《Chrome进行大小写字符敏感的内容查找》</a></div></blockquote><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/sorting_compare.html" title="八种排序算法效率比较">八种排序算法效率比较</a> (6)</li><li><a href="http://terence2008.info/archives/008.html" title="信春哥 死后四次原地满血复活">信春哥 死后四次原地满血复活</a> (0)</li><li><a href="http://terence2008.info/archives/spring_in_jdk_classes_loding_bug.html" title="Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题">Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题</a> (1)</li><li><a href="http://terence2008.info/archives/ajaxswing.html" title="AjaxSwing4.4.0授权码">AjaxSwing4.4.0授权码</a> (2)</li><li><a href="http://terence2008.info/archives/005.html" title="猜想2010年后的中国网络">猜想2010年后的中国网络</a> (0)</li><li><a href="http://terence2008.info/archives/009.html" title="让flash植入代码符合xhtml标准">让flash植入代码符合xhtml标准</a> (1)</li><li><a href="http://terence2008.info/archives/wordpress_database_optimize.html" title="WordPress数据库的一处性能优化">WordPress数据库的一处性能优化</a> (1)</li><li><a href="http://terence2008.info/archives/how_to_connect_eap_wifi.html" title="如何手动连接802.1x EAP证书加密WIFI">如何手动连接802.1x EAP证书加密WIFI</a> (1)</li><li><a href="http://terence2008.info/archives/kindle3_pinyin_input_method.html" title=" [完美版发布！] Kindle 3 原生系统3.4.2拼音输入法完美版安装包[最新版本0.4.2]"> [完美版发布！] Kindle 3 原生系统3.4.2拼音输入法完美版安装包[最新版本0.4.2]</a> (19)</li><li><a href="http://terence2008.info/archives/tinymce-firefox.html" title="TinyMCE编辑器对FireFox的兼容不太好">TinyMCE编辑器对FireFox的兼容不太好</a> (1)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/chrome_case_sensitive_search.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作</title>
		<link>http://terence2008.info/archives/hibernate_criteria_order.html</link>
		<comments>http://terence2008.info/archives/hibernate_criteria_order.html#comments</comments>
		<pubDate>Mon, 31 Mar 2014 04:51:59 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=494</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 先说一些题外话。众所周知，在<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/java" title="查看 Java 的全部文章">Java</a></span>持久层中有三种查询方式，分别是SQL、JPQL、和Criteria API。</p>
<h2>一、SQL</h2>
<p>&nbsp; &nbsp; &nbsp; 这个很好理解，一般小项目并且对安全性、效率性和灵活性没有特别需求的都会采用这个最原始的方法：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// 获得实体管理器</span>
EntityManager em <span style="color: #339933;">=</span> ...
<span style="color: #666666; font-style: italic;">// 建立SQL查询</span>
<span style="color: #003399;">String</span> getByFirstName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM contacts c WHERE c.first_name = ?1&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// 创建查询实例</span>
Query query <span style="color: #339933;">=</span> em.<span style="color: #006633;">createNativeQuery</span><span style="color: #009900;">&#40;</span>getByFirstName, Contact.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// 设置查询参数</span>
query.<span style="color: #006633;">setParameter</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #0000ff;">&quot;John&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// 获取结果</span>
<span style="color: #003399;">List</span> contacts <span style="color: #339933;">=</span> query.<span style="color: #006633;">getResultList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>上面的例子告诉我们3件事：</p>
<p>1）用SQL建立查询，无需学习新的查询语言；</p>
<p>2）创建的查询没有类型安全，在使用前必须计算查询结果；</p>
<p>3）在运行程序前必须验证查询的拼写或语法是否有错误。</p>
<h2>二、JPQL</h2>
<p>&nbsp; &nbsp; &nbsp;&nbsp;JPQL是基于字符串的查询语言，语法类似于SQL。因此学习JPQL相当容易，只要有一定的SQL基础。看下面的代码：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// 获得实体管理器</span>
EntityManager em <span style="color: #339933;">=</span> ...
<span style="color: #666666; font-style: italic;">// 建立JPQL查询</span>
<span style="color: #003399;">String</span> getByFirstName <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT c FROM Contact c WHERE c.firstName = :firstName&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// 创建查询实例</span>
TypedQuery<span style="color: #339933;">&lt;</span>Contact<span style="color: #339933;">&gt;</span> query <span style="color: #339933;">=</span> em.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>getByFirstName, Contact.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// 设置查询参数</span>
query.<span style="color: #006633;">setParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;firstName&quot;</span>, <span style="color: #0000ff;">&quot;John&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// 获取结果</span>
List<span style="color: #339933;">&lt;</span>Contact<span style="color: #339933;">&gt;</span> contacts <span style="color: #339933;">=</span> query.<span style="color: #006633;">getResultList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>上面的例子告诉我们3件事：</p>
<p>1）创建的查询是类型安全的，我们不必计算查询的结果；</p>
<p>2）JPQL查询字符串是易读、易于理解的；</p>
<p>3）创建的查询字符串在编译期间不会被验证。</p>
<h2>三、Criteria API</h2>
<p>&nbsp; &nbsp; &nbsp;&nbsp;Criteria API用于解决对接第三方ORM框架时让JPQL标准化。它用于构建查询定义对象，此对象会被翻译成可执行的SQL查询。Criteria API对于创建动态查询是一个极好的工具，它使得创建动态查询更简便，因为我们处理的是对象，而不是处理查询的字符串。缺点在于随着查询的复杂度的增加，查询定义对象的创建也会变得很繁琐，代码会更难读。下面的代码说明了这个问题：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// 获得实体管理器</span>
EntityManager em <span style="color: #339933;">=</span> ...
<span style="color: #666666; font-style: italic;">// 获得Criteria建立器</span>
CriteriaBuilder cb <span style="color: #339933;">=</span> em.<span style="color: #006633;">getCriteriaBuilder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// 建立Criteria查询</span>
CriteriaQuery<span style="color: #339933;">&lt;</span>Contact<span style="color: #339933;">&gt;</span> query <span style="color: #339933;">=</span> cb.<span style="color: #006633;">greateQuery</span><span style="color: #009900;">&#40;</span>Contact.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// 创建查询Root</span>
Root<span style="color: #339933;">&lt;</span>Contact<span style="color: #339933;">&gt;</span> root <span style="color: #339933;">=</span> query.<span style="color: #006633;">from</span><span style="color: #009900;">&#40;</span>Contact.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// 创建firstName的查询条件，使用静态元模型</span>
Predicate firstNameIs <span style="color: #339933;">=</span> cb.<span style="color: #006633;">equal</span><span style="color: #009900;">&#40;</span>root.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>Contact_.<span style="color: #006633;">firstName</span>, <span style="color: #0000ff;">&quot;John&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// 指定查询的where条件</span>
query.<span style="color: #006633;">where</span><span style="color: #009900;">&#40;</span>firstNameIs<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// 创建查询并获取结果</span>
TypedQuery<span style="color: #339933;">&lt;</span>Contact<span style="color: #339933;">&gt;</span> q <span style="color: #339933;">=</span> em.<span style="color: #006633;">createQuery</span><span style="color: #009900;">&#40;</span>query<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
List<span style="color: #339933;">&lt;</span>Contact<span style="color: #339933;">&gt;</span> contacts <span style="color: #339933;">=</span> q.<span style="color: #006633;">getResultList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>上面的例子告诉我们3件事：<br />
1）创建的查询是类型安全的，不必计算查询的结果；<br />
2）代码不如SQL或JPQL那么易读；<br />
3）由于是使用<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/java" title="查看 Java 的全部文章">Java</a></span> API处理，<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/java" title="查看 Java 的全部文章">Java</a></span>编译器会确保查询的语法正确。</p>
<h2>四、<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/hibernate" title="查看 Hibernate 的全部文章">Hibernate</a></span>的Criteria API架构</h2>
<p>&nbsp; &nbsp; &nbsp; 目前一般的中大型Java Web项目都会采用Spring和<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/hibernate" title="查看 Hibernate 的全部文章">Hibernate</a></span>框架进行开发，为了迎合统一面向对象化的代码管理，Criteria就显得比较好用了，在查询方法设计上可以灵活的根据Criteria的特点来方便地进行查询条件的组装。现在对<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/hibernate" title="查看 Hibernate 的全部文章">Hibernate</a></span>的Criteria用法进行总结：</p>
<p>&nbsp; &nbsp; &nbsp; Hibernate设计了CriteriaSpecification作为Criteria的父接口，下面提供了Criteria和DetachedCriteria。Criteria和DetachedCriteria的主要区别在于创建的形式不一样，Criteria是在线的，所以它是由Hibernate Session进行创建的；而DetachedCriteria是离线的，创建时无需Session，DetachedCriteria提供了2个静态方法forClass(Class)或forEntityName(Name)进行DetachedCriteria实例的创建。Spring框架提供了getHibernateTemplate().findByCriteria(detachedCriteria)方法可以很方便地根据DetachedCriteria来返回查询结果。Criteria和DetachedCriteria均可使用Criterion和Projection设置查询条件。可以设置FetchMode（联合查询抓取模式），设置排序方式。对于Criteria还可以设置FlushModel（冲刷Session方式）和LockMode（数据库锁模式）。</p>
<p>&nbsp; &nbsp; &nbsp; Hibernate具体的Criteria使用方式这里就不再赘述，官网文档里已经有比较详细的说明了。下面我就只举个平时开发中遇到的有关自定义SQL表达式的例子。</p>
<h2>五、Hibernate自定义SQL表达式的困惑</h2>
<p>&nbsp; &nbsp; &nbsp; 有人说Hibernate不灵活，估计主要就是体现在采用Criteria API时，对于自定义SQL表达式的支持比较缺乏人性化的设计，当然这只是个人之言，也有可能对架构还没有完全吃透。下面我就说下开发中遇到的问题，先上DAO代码：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> List<span style="color: #339933;">&lt;</span>com.<span style="color: #006633;">yun</span>.<span style="color: #006633;">dba</span>.<span style="color: #006633;">check</span>.<span style="color: #006633;">view</span>.<span style="color: #006633;">HostResource</span><span style="color: #339933;">&gt;</span> getHostResourceByCondition<span style="color: #009900;">&#40;</span>List<span style="color: #339933;">&lt;</span>SearchSupport<span style="color: #339933;">&gt;</span> searchList,
                                                                           <span style="color: #003399;">Integer</span> pageNo,
                                                                           <span style="color: #003399;">Integer</span> pageSize,
                                                                           <span style="color: #003399;">String</span> orderString<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">super</span>
    .<span style="color: #006633;">getByCondition</span><span style="color: #009900;">&#40;</span>getSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">createCriteria</span><span style="color: #009900;">&#40;</span>HostResource.<span style="color: #000000; font-weight: bold;">class</span>, <span style="color: #0000ff;">&quot;hr&quot;</span><span style="color: #009900;">&#41;</span>, searchList,
        pageNo, pageSize<span style="color: #009900;">&#41;</span>
    .<span style="color: #006633;">addOrder</span><span style="color: #009900;">&#40;</span>Order.<span style="color: #006633;">desc</span><span style="color: #009900;">&#40;</span>orderString<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #006633;">setProjection</span><span style="color: #009900;">&#40;</span>
        Projections
            .<span style="color: #006633;">projectionList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;statDate&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;statDate&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;gmtModified&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;gmtModified&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;hostId&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hostId&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;region&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;region&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;clusterName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;clusterName&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;ip&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ip&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;dbType&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dbType&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;groupName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;groupName&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;hostCreated&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hostCreated&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;hostAvail&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hostAvail&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;clusterAvail&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;clusterAvail&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;memTotal&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;memTotal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;diskTotal&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;diskTotal&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;activeInsCnt&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;activeInsCnt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;memSelled&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;memSelled&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;diskSelled&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;diskSelled&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;currInsCnt&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;currInsCnt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;diskCurr&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;diskCurr&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;rssMem&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;rssMem&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>Projections.<span style="color: #006633;">property</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hr.&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;dbVersion&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">as</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dbVersion&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            .<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>
                Projections
                    .<span style="color: #006633;">sqlProjection</span><span style="color: #009900;">&#40;</span>
                        <span style="color: #0000ff;">&quot;round(mem_selled/mem_total*100,2) as memselledRate,round(disk_selled/disk_total*100,2) as diskselledRate,round(disk_curr/disk_total*100,2) as diskcurrRate&quot;</span>,
                        <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> <span style="color: #0000ff;">&quot;memselledRate&quot;</span>, <span style="color: #0000ff;">&quot;diskselledRate&quot;</span>, <span style="color: #0000ff;">&quot;diskcurrRate&quot;</span> <span style="color: #009900;">&#125;</span>,
                        <span style="color: #000000; font-weight: bold;">new</span> Type<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#123;</span> StandardBasicTypes.<span style="color: #006633;">FLOAT</span>, StandardBasicTypes.<span style="color: #006633;">FLOAT</span>,
                                StandardBasicTypes.<span style="color: #006633;">FLOAT</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #006633;">setResultTransformer</span><span style="color: #009900;">&#40;</span>
        <span style="color: #000000; font-weight: bold;">new</span> AliasToBeanResultTransformer<span style="color: #009900;">&#40;</span>com.<span style="color: #006633;">yun</span>.<span style="color: #006633;">dba</span>.<span style="color: #006633;">check</span>.<span style="color: #006633;">view</span>.<span style="color: #006633;">HostResource</span>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    .<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 首先这个DAO是个带分页输出的Criteria查询，继承父类分页DAO后对于本表进行属性定义，sqlProjection方法就是Hibernate&nbsp;Criteria API里对自定义SQL表达式的支持方法。然后对输出的对象进行结构改造，基于原来的HostResource表类再增加一些自定义SQL表达式列，把新的HostResource类放在view包里，这么做的意义在于进行Order by操作的时候自定义SQL表达式投影列也可以做到分页排序输出。</p>
<p>&nbsp; &nbsp; &nbsp; 看似一切都很完美，但其实不然，在调试中才发现原来Order.desc(orderString)方法竟然不支持对sqlProjection方法中新生成的自定义SQL表达式投影列名进行排序。现在有两种解决方案，一个是放弃Criteria API转而采用createSQLQuery方法对该DAO进行JPQL改造；另一种方法就是深入研究Hibernate&nbsp;Criteria API源码，找出解决方法。最后选择的动力是重构一个JPQL太麻烦，还不如研究源码靠谱些。</p>
<h2>六、究其原因</h2>
<p>&nbsp; &nbsp; &nbsp; 查看org.hibernate.criterion.Order类可以发现，toSqlString方法对传入的列名参数及其排序方式进行了处理：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toSqlString<span style="color: #009900;">&#40;</span>Criteria criteria, CriteriaQuery criteriaQuery<span style="color: #009900;">&#41;</span> 
<span style="color: #000000; font-weight: bold;">throws</span> HibernateException <span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> columns <span style="color: #339933;">=</span> criteriaQuery.<span style="color: #006633;">getColumnsUsingProjection</span><span style="color: #009900;">&#40;</span>criteria, propertyName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	Type type <span style="color: #339933;">=</span> criteriaQuery.<span style="color: #006633;">getTypeUsingProjection</span><span style="color: #009900;">&#40;</span>criteria, propertyName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">StringBuffer</span> fragment <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>columns.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		SessionFactoryImplementor factory <span style="color: #339933;">=</span> criteriaQuery.<span style="color: #006633;">getFactory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">boolean</span> lower <span style="color: #339933;">=</span> ignoreCase <span style="color: #339933;">&amp;&amp;</span> type.<span style="color: #006633;">sqlTypes</span><span style="color: #009900;">&#40;</span> factory <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">==</span><span style="color: #003399;">Types</span>.<span style="color: #006633;">VARCHAR</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lower<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			fragment.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span> factory.<span style="color: #006633;">getDialect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getLowercaseFunction</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
				.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'('</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		fragment.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span> columns<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lower<span style="color: #009900;">&#41;</span> fragment.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">')'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		fragment.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span> ascending <span style="color: #339933;">?</span> <span style="color: #0000ff;">&quot; asc&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot; desc&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> i<span style="color: #339933;">&lt;</span>columns.<span style="color: #006633;">length</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> fragment.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;, &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">return</span> fragment.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 可以发现getColumnsUsingProjection方法只是对Criteria已定义的投影列做了处理，对于那些自定义SQL表达式投影列名是排除在外的，这不得不说是个遗憾，所以sqlProjection方法就有点类似于鸡肋的感觉了。</p>
<h2>七、解决方法</h2>
<p>&nbsp; &nbsp; &nbsp; 知道了原理接下来解决方法就简单了，直接继承org.hibernate.criterion.Order类，清空toSqlString方法，取消Order by的Criteria投影支持：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.criterion.Order</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.criterion.CriteriaQuery</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.Criteria</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hibernate.HibernateException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> OrderBySqlFormula <span style="color: #000000; font-weight: bold;">extends</span> Order <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> sqlFormula<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> OrderBySqlFormula<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> sqlFormula<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>sqlFormula, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">sqlFormula</span> <span style="color: #339933;">=</span> sqlFormula<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> sqlFormula<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toSqlString<span style="color: #009900;">&#40;</span>Criteria criteria, CriteriaQuery criteriaQuery<span style="color: #009900;">&#41;</span>
                                                                             <span style="color: #000000; font-weight: bold;">throws</span> HibernateException <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> sqlFormula<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Order sqlFormula<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> sqlFormula<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> OrderBySqlFormula<span style="color: #009900;">&#40;</span>sqlFormula<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 使用的时候把Order.desc(orderString)改为OrderBySqlFormula.sqlFormula(orderString+" desc")就可以了，唯一的缺点就是Order by的时候所有的列名都不能使用Criteria投影列名了，取而代之的是表中真实的列名，这点需要注意。但不管怎么说还是做到了用最少的代码修改代价达到了既定的需求目标，尽管代码改的有些丑陋。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作" href="http://terence2008.info/archives/hibernate_criteria_order.html">《Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/ajaxswing.html" title="AjaxSwing4.4.0授权码">AjaxSwing4.4.0授权码</a> (2)</li><li><a href="http://terence2008.info/archives/javamail_on_jdk8_ssl_problem.html" title="Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案">Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案</a> (0)</li><li><a href="http://terence2008.info/archives/spring_in_jdk_classes_loding_bug.html" title="Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题">Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题</a> (1)</li><li><a href="http://terence2008.info/archives/eclipse-optimizing.html" title="Eclipse性能优化实践">Eclipse性能优化实践</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/hibernate_criteria_order.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>老版本Ubuntu 11.04等的源列表</title>
		<link>http://terence2008.info/archives/ubuntu_old_sources.html</link>
		<comments>http://terence2008.info/archives/ubuntu_old_sources.html#comments</comments>
		<pubDate>Mon, 03 Mar 2014 08:08:20 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[服务器运维]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[运维]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=491</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 比较喜欢<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/ubuntu" title="查看 Ubuntu 的全部文章">Ubuntu</a></span>之前的Gnome 2.x经典界面，现在的Unity简直是反人类，抄Mac OS不说，但好歹要学人家操作简单易用啊，我去。。<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/ubuntu" title="查看 Ubuntu 的全部文章">Ubuntu</a></span>最后一个支持Gnome 2.x经典界面的版本是11.04，此后反人类界面登场了，连12.04 LTS版也不例外，虽然可以安装gnome-session-fallback包回到2.x时的经典桌面样子，但模拟始终是模拟，很多细节地方还是无法替代2.x时代的辉煌。</p>
<p>&nbsp; &nbsp; &nbsp; 但问题来了，11.04不是LTS版本（LTS版的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/ubuntu" title="查看 Ubuntu 的全部文章">Ubuntu</a></span>有最长五年的支持周期），大概在2012年10月的时候就停止更新支持了，这也意味着它的官方源也就伴随着下线了，包括其他第三方镜像源，一般都是和官方源同步的。因此，直接用原来的源列表是不能安装更新软件的，这下如果要在这类老旧系统上安装apt包可怎么办呢？其实大可不必担心，Ubuntu已经为我们考虑到了这个情况，官方专门出了一个old-release镜像服务器<a href="http://old-releases.ubuntu.com/" target="_blank">http://old-releases.ubuntu.com/</a>，我们可以用这个源来更新系统，所需要做的工作就是把原来的源地址替换成这个就行。</p>
<p>&nbsp; &nbsp; &nbsp; 比如我在用的11.04，打开/etc/apt/sources.list文件，清空原来的内容，填入以下的源列表地址：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># deb cdrom:[Ubuntu 11.04 _Natty Narwhal_ - Release i386 (20110427.1)]/ natty main restricted</span>
&nbsp;
deb http:<span style="color: #000000; font-weight: bold;">//</span>old-releases.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> natty main restricted universe multiverse
deb http:<span style="color: #000000; font-weight: bold;">//</span>old-releases.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> natty-security main restricted universe multiverse
deb http:<span style="color: #000000; font-weight: bold;">//</span>old-releases.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> natty-updates main restricted universe multiverse
deb http:<span style="color: #000000; font-weight: bold;">//</span>old-releases.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> natty-proposed main restricted universe multiverse
deb http:<span style="color: #000000; font-weight: bold;">//</span>old-releases.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu<span style="color: #000000; font-weight: bold;">/</span> natty-backports main restricted universe multiverse
<span style="color: #666666; font-style: italic;"># deb-src http://old-releases.ubuntu.com/ubuntu/ natty main restricted universe multiverse</span>
<span style="color: #666666; font-style: italic;"># deb-src http://old-releases.ubuntu.com/ubuntu/ natty-security main restricted universe multiverse</span>
<span style="color: #666666; font-style: italic;"># deb-src http://old-releases.ubuntu.com/ubuntu/ natty-updates main restricted universe multiverse</span>
<span style="color: #666666; font-style: italic;"># deb-src http://old-releases.ubuntu.com/ubuntu/ natty-proposed main restricted universe multiverse</span>
<span style="color: #666666; font-style: italic;"># deb-src http://old-releases.ubuntu.com/ubuntu/ natty-backports main restricted universe multiverse</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## Uncomment the following two lines to add software from Canonical's</span>
<span style="color: #666666; font-style: italic;">## 'partner' repository.</span>
<span style="color: #666666; font-style: italic;">## This software is not part of Ubuntu, but is offered by Canonical and the</span>
<span style="color: #666666; font-style: italic;">## respective vendors as a service to Ubuntu users.</span>
deb http:<span style="color: #000000; font-weight: bold;">//</span>archive.canonical.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu natty partner
<span style="color: #666666; font-style: italic;"># deb-src http://archive.canonical.com/ubuntu natty partner</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## This software is not part of Ubuntu, but is offered by third-party</span>
<span style="color: #666666; font-style: italic;">## developers who want to ship their latest software.</span>
deb http:<span style="color: #000000; font-weight: bold;">//</span>extras.ubuntu.com<span style="color: #000000; font-weight: bold;">/</span>ubuntu oneiric main
<span style="color: #666666; font-style: italic;"># deb-src http://extras.ubuntu.com/ubuntu oneiric main</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 然后再用apt-get update更新下apt缓存，是不是不会再报了404错误了呀。当然，对于其他Ubuntu旧版本只需要将11.04的版本代号natty改成其他版本代号即可，这样过期后的版本也可以继续使用了。需要注意的是old-release镜像服务器位于欧洲，国内访问它可能会比较慢，需要耐心等待。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="老版本Ubuntu 11.04等的源列表" href="http://terence2008.info/archives/ubuntu_old_sources.html">《老版本Ubuntu 11.04等的源列表》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/ubuntu-service-autostart.html" title="Ubuntu的两种服务自启动模式">Ubuntu的两种服务自启动模式</a> (0)</li><li><a href="http://terence2008.info/archives/blog_maintenance.html" title="博客维护日记">博客维护日记</a> (0)</li><li><a href="http://terence2008.info/archives/backup-database-webroot.html" title="定时备份mysql和网站目录文件">定时备份mysql和网站目录文件</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/ubuntu_old_sources.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>博客维护日记</title>
		<link>http://terence2008.info/archives/blog_maintenance.html</link>
		<comments>http://terence2008.info/archives/blog_maintenance.html#comments</comments>
		<pubDate>Wed, 19 Feb 2014 14:34:52 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[服务器运维]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[优化]]></category>
		<category><![CDATA[运维]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=482</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 从博客重新启用至今已经过去了将近4个月的时间，除了之前提到的<a href="http://terence2008.info/archives/i-am-back.html" target="_blank">对服务器进行最大化优化</a>外，却一直忽略了对于博客程序本身的维护，毕竟是2010年时候的wordpress代码，包括各种插件都已经很过时了，加上最近才发现的一些由于插件问题而带来的bug，因此升级代码是非常必要的。</p>
<p>&nbsp; &nbsp; &nbsp; 首先是插件的升级维护工作，下面是相对于<a href="http://terence2008.info/archives/my-plugins.html" target="_blank">之前所使用的插件</a>，到现在经过改动的插件列表：</p>
<p><strong>1、<a href="http://wordpress.org/plugins/wp-db-backup/" target="_blank">WP-DB-Backup</a></strong></p>
<p>&nbsp; &nbsp; &nbsp; 升级插件版本，解决数据库定时备份的bug，其实自从用了<a href="http://terence2008.info/archives/backup-database-webroot.html" target="_blank">脚本定时备份mysql和网站目录文件</a>后，我就把这个插件给禁用了，MySQL的dump效率不知比mysql-php模块快了多少。</p>
<p><strong>2、<a href="http://wordpress.org/plugins/keep-blanks/" target="_blank">Keep Blanks</a></strong></p>
<p>&nbsp; &nbsp; &nbsp; 新安装插件，<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/wordpress" title="查看 WordPress 的全部文章">WordPress</a></span>所使用的TinyMCE编辑器的兼容问题源自博客里的一篇<a href="http://terence2008.info/archives/tinymce-firefox.html" target="_blank">老日志</a>，在可视化编辑框的模式下打入空格后切换到HTML编辑模式，然后再切回来就会被自作聪明的去掉了，这款插件解决了这个问题。</p>
<p><strong>3、<a href="http://wordpress.org/plugins/nospamnx/" target="_blank">NoSpamNX</a></strong></p>
<p>&nbsp; &nbsp; &nbsp; 升级插件版本，解决拦截垃圾评论失效问题。</p>
<p><strong>4、<a href="http://wordpress.org/plugins/wp-super-cache/" target="_blank">WP Super Cache</a></strong></p>
<p>&nbsp; &nbsp; &nbsp; 升级插件版本，新版本的静态化缓存功能更为强大，更新了Mod Rewrite规则，支持WP-T-Wap插件生成的wap手机版网页的静态化缓存。</p>
<p><strong>5、<a href="http://wordpress.org/plugins/wp-downloadcounter/" target="_blank">wp-downloadcounter</a></strong></p>
<p>&nbsp; &nbsp; &nbsp; 解决了下载计数插件代码里的一个逻辑错误，修改downloadcounter-config.php文件第102行，将“strpos($url-&gt;download_url, get_option('siteurl')) == 0”改为“strpos($url-&gt;download_url, get_option('siteurl')) === 0”。三个等号的含义是完全等于运算，不仅比较值，而且还比较值的类型，只有两者一致才为真，两个等号是不比较值的类型的。原来的代码混淆了0和false的判断，导致下载计数的链接如果是非本地的话，apache的error_log会记录下插件错误的调用了file指令。</p>
<p><strong>6、<a href="http://share.baidu.com/help/system/wordpress" target="_blank">baidushare_wp</a></strong></p>
<p>&nbsp; &nbsp; &nbsp; 新安装插件，百度分享用来代替之前的<a href="http://wordpress.org/plugins/daitui-service/" target="_blank">代推</a>，原因是代推已经很久没有更新了，分享网站很多都已经不可用，加上最近几天发现代推的服务器都打不开了，遂换之，新的百度分享插件做的还是挺漂亮的，分享链接显示在了正文的后面，分享网站入口也很全，还能显示已经分享出去的次数，方便跟踪统计。但不知为什么现在这个插件在<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/wordpress" title="查看 WordPress 的全部文章">WordPress</a></span>官网上下架了，只能在百度分享官网上下到。另外由于插件代码本身已经很久没更新了，逻辑有缺陷，最新生成的百度分享js代码中的“|”分隔符会导致插件设置保存失败，所以需要对js代码进行处理，解决方法就是将里面的代码“getElementsByTagName('head')[0]||body”二挑一，我选择前者，虽然采取后者可以照顾到网页的加载先后顺序，但经过实验发现这样会造成IE6下网页渲染失败，所以还是把js放在head最后比较稳妥。</p>
<p><strong>7、<a href="http://wordpress.org/plugins/wp-useragent/" target="_blank">WP-UserAgent</a></strong></p>
<p>&nbsp; &nbsp; &nbsp; 升级插件版本，显示评论人的浏览器和操作系统名称，新版本增加了一些新的user agent字符串，修复了IE11的显示，增加了隐藏未知user agent字符串的功能。</p>
<p><strong>8、<a href="http://wordpress.org/plugins/wordpress-thread-comment/" target="_blank">WordPress Thread Comment</a></strong></p>
<p>&nbsp; &nbsp; &nbsp; 使用AJAX技术局部刷新评论的插件，该插件启用后在Chrome的控制台里会有“Resource interpreted as Script but transferred with MIME type text/html”的警告。这是由于服务器端给浏览器发回的HTTP响应头中content-type值是text/plain（默认），而所期望返回的是JavaScript类型的，所以浏览器提示上面的警告信息。修改方法就是wp-thread-comment.js.php文件中取消对“header("Content-Type:text/javascript");”的注释，有三处，不知道作者是怎么想的，为什么好端端的写完还要再注释掉。</p>
<p><strong>9、<a href="http://wordpress.org/plugins/lightbox-plus/" target="_blank">Lightbox Plus</a></strong></p>
<p>&nbsp; &nbsp; &nbsp; 正文图片灯箱展示插件，该插件一大优点就是对IE6浏览器做了兼容工作，但bug也恰恰出在这儿。在我迁移完博客后，发现IE6浏览器下的灯箱展示CSS布局异常。究其原因该插件把IE6相关的配置选项保存在了wp_options表的“lightboxplus_style_path”键名里，其对应的键值就是IE6下所用到的CSS文件路径，是个绝对路径，迁移服务器后不能自动修改其绝对路径地址，故显示不正常，解决方法只能是手工修改数据库里的键值了。</p>
<p><strong>10、<a href="http://wordpress.org/plugins/wp-t-wap/" target="_blank">WP-T-Wap</a></strong></p>
<p>&nbsp; &nbsp; &nbsp; 生成wap手机版网页的插件，这款插件的问题比较大。先说小的修改，为了能让代码高亮显示，我安装了<a href="http://wordpress.org/plugins/wp-syntax/" target="_blank">WP-Syntax</a>插件，普通电脑主题上用着效果还不错，但代码显示在wap页面上就不能自动换行了，直接超出到了屏幕外面，经过排查发现是由于<a href="http://wordpress.org/plugins/wp-syntax/" target="_blank">WP-Syntax</a>插件对应的css文件没有在wap页面上加载，解决方法就是在index-wap2.php文件的head标签最后添加“&lt;link rel="stylesheet" href="&lt;?php bloginfo('template_url'); ?&gt;/wp-syntax.css" type="text/css" media="screen" /&gt;”即可。另外我在wap页面最后添加了追踪代码供分析监控。</p>
<p>&nbsp; &nbsp; &nbsp; 然后说说大问题的，<a href="http://wordpress.org/plugins/wp-t-wap/" target="_blank">WP-T-Wap</a>插件号称与<a href="http://wordpress.org/plugins/wordpress-23-related-posts-plugin/" target="_blank">WordPress Related Posts</a>插件相兼容，能把相关日志列表显示在正文后面，但这个插件已经很久没有更新了，加上<a href="http://wordpress.org/plugins/wordpress-23-related-posts-plugin/" target="_blank">WordPress Related Posts</a>插件变化又很大，导致<a href="http://wordpress.org/plugins/wp-t-wap/" target="_blank">WP-T-Wap</a>插件的相关日志列表显示不正常，其代码块需要重写，以匹配新的函数接口和数据库字段存储方式。下面我就把需要修改的地方贴出来，覆盖位置在functions.php文件的_wp23_get_related_posts()函数体里：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #000000; font-weight: bold;">function</span> _wp23_get_related_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #666666; font-style: italic;">//改动整个函数，匹配wordpress-23-related-posts-plugin插件的新接口</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">return</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
	<span style="color: #000088;">$now</span> <span style="color: #339933;">=</span> current_time<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mysql'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$tags</span> <span style="color: #339933;">=</span> wp_get_post_tags<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//print_r($tags);</span>
&nbsp;
	<span style="color: #000088;">$taglist</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;'&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">term_id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$tagcount</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tagcount</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$tagcount</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$taglist</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$taglist</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;, '&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&quot;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">term_id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;'&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$wp_rp</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;wp_rp&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//读取配置，这里读出的是数组</span>
	<span style="color: #000088;">$limit</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_rp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wp_rp_limit'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$limit</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$limitclause</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;LIMIT <span style="color: #006699; font-weight: bold;">$limit</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$exclude</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_rp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wp_rp_exclude'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$exclude</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$excludeclause</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;AND p.ID NOT IN (SELECT tr.object_id FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_relationships</span> tr LEFT JOIN <span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_taxonomy</span> tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = 'category' AND tt.term_id REGEXP '[<span style="color: #006699; font-weight: bold;">$exclude</span>]')&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT DISTINCT p.ID, p.post_title, p.post_date, p.comment_count, count(t_r.object_id) as cnt FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_taxonomy</span> t_t, <span style="color: #006699; font-weight: bold;">$wpdb-&gt;term_relationships</span> t_r, <span style="color: #006699; font-weight: bold;">$wpdb-&gt;posts</span> p WHERE t_t.taxonomy ='post_tag' AND t_t.term_taxonomy_id = t_r.term_taxonomy_id AND t_r.object_id  = p.ID AND (t_t.term_id IN (<span style="color: #006699; font-weight: bold;">$taglist</span>)) AND p.ID != <span style="color: #006699; font-weight: bold;">$post-&gt;ID</span> AND p.post_status = 'publish' AND p.post_date_gmt &lt; '<span style="color: #006699; font-weight: bold;">$now</span>' <span style="color: #006699; font-weight: bold;">$excludeclause</span> GROUP BY t_r.object_id ORDER BY cnt DESC, p.post_date_gmt DESC <span style="color: #006699; font-weight: bold;">$limitclause</span>;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//echo $q;</span>
&nbsp;
	<span style="color: #000088;">$related_posts</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$wp23_RP_title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_rp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wp_rp_title'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$wp23_RP_title</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$wp23_RP_title</span><span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Related Posts&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'wp_related_posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$related_posts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000088;">$wp23_no_RP</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_rp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wp_no_rp'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$wp23_no_RP</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp23_no_RP</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;popularity&quot;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'akpc_most_popular'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$wp23_no_RP</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$wp23_no_RP_text</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_rp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wp_no_rp_text'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp23_no_RP</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;text&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$wp23_no_RP_text</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$wp23_no_RP_text</span><span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No Related Posts&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'wp_related_posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//国际化字段之前错了，textdomain也写错了，下同</span>
			<span style="color: #000088;">$output</span>  <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;li&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$wp23_no_RP_text</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>	<span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_random_posts'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$wp23_no_RP</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;random&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$wp23_no_RP_text</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$wp23_no_RP_text</span><span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Random Posts&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'wp_related_posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$related_posts</span> <span style="color: #339933;">=</span> wp_get_random_posts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$limitclause</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//修改调用函数接口</span>
			<span style="color: #009900;">&#125;</span>	<span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_most_commented_posts'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$wp23_no_RP</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;commented&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$wp23_no_RP_text</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$wp23_no_RP_text</span><span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Most Commented Posts&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'wp_related_posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$related_posts</span> <span style="color: #339933;">=</span> wp_get_most_commented_posts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$limitclause</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>	<span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_most_popular_posts'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$wp23_no_RP</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;popularity&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$wp23_no_RP_text</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$wp23_no_RP_text</span><span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Most Popular Posts&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'wp_related_posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$related_posts</span> <span style="color: #339933;">=</span> wp_get_most_popular_posts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$limitclause</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">return</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Something wrong&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'wp_related_posts'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #000088;">$wp23_RP_title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp23_no_RP_text</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$related_posts</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$related_post</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;li&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$show_date</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_rp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wp_rp_date'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$show_date</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$dateformat</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'date_format'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span>   mysql2date<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dateformat</span><span style="color: #339933;">,</span> <span style="color: #000088;">$related_post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_date</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot; -- &quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">.</span>_get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$related_post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; title=&quot;'</span><span style="color: #339933;">.</span>wptexturize<span style="color: #009900;">&#40;</span><span style="color: #000088;">$related_post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span>wptexturize<span style="color: #009900;">&#40;</span><span style="color: #000088;">$related_post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$show_comments_count</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_rp</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wp_rp_comments'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$show_comments_count</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot; (&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$related_post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_count</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;)&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">'&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span>  <span style="color: #0000ff;">'&lt;div id=&quot;infoblock&quot;&gt;&lt;h2&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$wp23_RP_title</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/h2&gt;&lt;/div&gt;'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;div class=&quot;page&quot;&gt;&lt;ol id=&quot;pages&quot;&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$output</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/ol&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><strong>11、<a href="http://wordpress.org/plugins/google-sitemap-generator/" target="_blank">Google XML Sitemaps</a></strong></p>
<p>&nbsp; &nbsp; &nbsp; 升级插件版本，修复了Bing的Sitemaps提交入口，去除了雅虎搜索的提交。另外我注释掉了sitemap-core.php文件中的$this-&gt;AddElement(new GoogleSitemapGeneratorDebugEntry("generator=\"wordpress/" . get_bloginfo('version') . "\""));防止sitemap.xml文件中泄漏<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/wordpress" title="查看 WordPress 的全部文章">WordPress</a></span>版本号。</p>
<p>&nbsp;</p>
<p>&nbsp; &nbsp; &nbsp; 修改完了插件代码，最后再是<a href="http://wordpress.org/themes/inove" target="_blank">iNove</a>主题中的functions.php文件，修改了一些WordPress核心级别的功能，添加下面的代码在文件开头：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/** 禁止评论内容自动添加链接，防止广告 */</span>
remove_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'comment_text'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'make_clickable'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/** 禁止wp输出版本号 */</span>
remove_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wp_generator'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> remove_wordpress_version<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_generator'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'remove_wordpress_version'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/** 禁用正文中自作聪明地把英文标点转换成中文标点 */</span>
remove_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wptexturize'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/** 在正文最后添加版权声明 */</span>
<span style="color: #000000; font-weight: bold;">function</span> feed_copyright<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> or is_feed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'
&lt;blockquote&gt;'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'
&lt;div&gt; 　&amp;raquo; 转载请注明来源：&lt;a title=&quot;'</span> <span style="color: #339933;">.</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; href=&quot;'</span> <span style="color: #339933;">.</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;'</span> <span style="color: #339933;">.</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt; &amp;raquo; &lt;a rel=&quot;bookmark&quot; title=&quot;'</span> <span style="color: #339933;">.</span> get_the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; href=&quot;'</span> <span style="color: #339933;">.</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot;&gt;《'</span> <span style="color: #339933;">.</span> get_the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'》&lt;/a&gt;&lt;/div&gt;
&nbsp;
'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$content</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/blockquote&gt;
&nbsp;
'</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'feed_copyright'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 写完这篇日记才发现原来改动了这么多地方，还是记录下来比较好，这下博客又能欢快地奔跑好一段时间了~</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="博客维护日记" href="http://terence2008.info/archives/blog_maintenance.html">《博客维护日记》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/backup-database-webroot.html" title="定时备份mysql和网站目录文件">定时备份mysql和网站目录文件</a> (0)</li><li><a href="http://terence2008.info/archives/wordpress_database_optimize.html" title="WordPress数据库的一处性能优化">WordPress数据库的一处性能优化</a> (1)</li><li><a href="http://terence2008.info/archives/ubuntu_old_sources.html" title="老版本Ubuntu 11.04等的源列表">老版本Ubuntu 11.04等的源列表</a> (1)</li><li><a href="http://terence2008.info/archives/ubuntu-service-autostart.html" title="Ubuntu的两种服务自启动模式">Ubuntu的两种服务自启动模式</a> (0)</li><li><a href="http://terence2008.info/archives/i-am-back.html" title="时隔三年我又回来啦">时隔三年我又回来啦</a> (2)</li><li><a href="http://terence2008.info/archives/tinymce-firefox.html" title="TinyMCE编辑器对FireFox的兼容不太好">TinyMCE编辑器对FireFox的兼容不太好</a> (1)</li><li><a href="http://terence2008.info/archives/my-plugins.html" title="我正在使用的插件列表">我正在使用的插件列表</a> (1)</li><li><a href="http://terence2008.info/archives/change-space.html" title="换空间了">换空间了</a> (1)</li><li><a href="http://terence2008.info/archives/013.html" title="Google阅读器里RSS的显示问题">Google阅读器里RSS的显示问题</a> (0)</li><li><a href="http://terence2008.info/archives/010.html" title="网页中连续字符手动换行的方法">网页中连续字符手动换行的方法</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/blog_maintenance.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5+CSS3《驴子跳》网页游戏源码</title>
		<link>http://terence2008.info/archives/html5_css3_lvzitiao_source.html</link>
		<comments>http://terence2008.info/archives/html5_css3_lvzitiao_source.html#comments</comments>
		<pubDate>Mon, 10 Feb 2014 05:32:01 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[游戏]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=471</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 分享一个《驴子跳》<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%b8%b8%e6%88%8f" title="查看 游戏 的全部文章">游戏</a></span>源码，制作很漂亮的一款HTML5+CSS3的网页<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%b8%b8%e6%88%8f" title="查看 游戏 的全部文章">游戏</a></span>，还配有音乐，很酷很刺激，想研究HTML5技术的朋友，可不要错过这款网页游戏哦，虽然是游戏，但却考验了作者很综合的HTML5编程水平。</p>
<p><a href="http://terence2008.info/wp-content/uploads/2014/02/lvzitiao_1.png" rel="lightbox[471]" title="lvzitiao_1"><img class="alignnone size-medium wp-image-480" title="lvzitiao_1" src="http://terence2008.info/wp-content/uploads/2014/02/lvzitiao_1-180x300.png" alt="" width="180" height="300" /></a>&nbsp;<a href="http://terence2008.info/wp-content/uploads/2014/02/lvzitiao_2.png" rel="lightbox[471]" title="lvzitiao_2"><img class="alignnone size-medium wp-image-474" title="lvzitiao_2" src="http://terence2008.info/wp-content/uploads/2014/02/lvzitiao_2-179x300.png" alt="" width="179" height="300" /></a></p>
<p><a title="最后下载:2026年03月14日,下载952次" href="http://terence2008.info/downloads/HTML5_CSS3_dummy_donkey.7z">HTML5_CSS3_dummy_donkey.7z</a></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="HTML5+CSS3《驴子跳》网页游戏源码" href="http://terence2008.info/archives/html5_css3_lvzitiao_source.html">《HTML5+CSS3《驴子跳》网页游戏源码》</a></div></blockquote><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/002.html" title="那些曾经让你乐得死去活来的QQ签名">那些曾经让你乐得死去活来的QQ签名</a> (0)</li><li><a href="http://terence2008.info/archives/backup-database-webroot.html" title="定时备份mysql和网站目录文件">定时备份mysql和网站目录文件</a> (0)</li><li><a href="http://terence2008.info/archives/chrome_case_sensitive_search.html" title="Chrome进行大小写字符敏感的内容查找">Chrome进行大小写字符敏感的内容查找</a> (1)</li><li><a href="http://terence2008.info/archives/ubuntu_old_sources.html" title="老版本Ubuntu 11.04等的源列表">老版本Ubuntu 11.04等的源列表</a> (1)</li><li><a href="http://terence2008.info/archives/android-iphone-girl.html" title="智能手机的另一大功能——造星">智能手机的另一大功能——造星</a> (2)</li><li><a href="http://terence2008.info/archives/005.html" title="猜想2010年后的中国网络">猜想2010年后的中国网络</a> (0)</li><li><a href="http://terence2008.info/archives/008.html" title="信春哥 死后四次原地满血复活">信春哥 死后四次原地满血复活</a> (0)</li><li><a href="http://terence2008.info/archives/eclipse-optimizing.html" title="Eclipse性能优化实践">Eclipse性能优化实践</a> (0)</li><li><a href="http://terence2008.info/archives/wordpress_database_optimize.html" title="WordPress数据库的一处性能优化">WordPress数据库的一处性能优化</a> (1)</li><li><a href="http://terence2008.info/archives/ssl_cdn_choose.html" title="关于SSL证书与CDN加速的选择">关于SSL证书与CDN加速的选择</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/html5_css3_lvzitiao_source.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Chrome和Firefox的最早Release版本</title>
		<link>http://terence2008.info/archives/chrome_firefox_earliest_release.html</link>
		<comments>http://terence2008.info/archives/chrome_firefox_earliest_release.html#comments</comments>
		<pubDate>Thu, 30 Jan 2014 06:09:05 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[浏览器]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=466</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 今天惯例更新了下自己电脑上的Chrome后突发奇想，打开<a href="http://html5test.com/" target="_blank">html5test</a>网站，去检测Chrome对<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/html" title="查看 html 的全部文章">html</a></span>特性的支持度。发现它的确是独领风骚，把其他<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%b5%8f%e8%a7%88%e5%99%a8" title="查看 浏览器 的全部文章">浏览器</a></span>远远的甩在了后面，版本32.0.1700.102达到了503分，而Firefox 26才446分。</p>
<p>&nbsp; &nbsp; &nbsp; 于是好奇心驱使，想去找到Chrome和Firefox各自最早的release版本的项目源码，通过一番查找总算有些收获。Chrome 1.0.154.53 发布于2009.3.24，其对应的Chromium项目源码<a href="http://src.chromium.org/viewvc/chrome/releases/1.0.154.53/src/" target="_blank">地址在此</a>；而Firefox则比Chrome早了很多，最早的release版本号为1.0，发布于2004.11.9，其对应的mozilla社区项目源码<a href="ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/1.0/source/" target="_blank">地址在此</a>。</p>
<p>&nbsp; &nbsp; &nbsp; Chrome和Firefox最初release版本的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/html" title="查看 html 的全部文章">html</a></span>支持特性评分见下图所示，同时参与比较的还有IE6、Chrome 32和Firefox 26（都是release channel版本，<a href="http://html5test.com/compare/browser/chrome-1/firefox-1/ie-6/chrome-32/firefox-26.html" target="_blank">地址见此</a>）：</p>
<p><a href="http://terence2008.info/wp-content/uploads/2014/01/browser_compare.png" rel="lightbox[466]" title="browser_compare"><img class="alignnone size-medium wp-image-467" title="browser_compare" src="http://terence2008.info/wp-content/uploads/2014/01/browser_compare-300x236.png" alt="" width="300" height="236" /></a></p>
<p>&nbsp; &nbsp; &nbsp; 可见最初版本的Chrome和Firefox都和IE6差不多，但随着现代<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%b5%8f%e8%a7%88%e5%99%a8" title="查看 浏览器 的全部文章">浏览器</a></span>技术的发展，IE6真的老了，最新的IE11也才363分，微软加油啊！</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="Chrome和Firefox的最早Release版本" href="http://terence2008.info/archives/chrome_firefox_earliest_release.html">《Chrome和Firefox的最早Release版本》</a></div></blockquote><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/chrome_case_sensitive_search.html" title="Chrome进行大小写字符敏感的内容查找">Chrome进行大小写字符敏感的内容查找</a> (1)</li><li><a href="http://terence2008.info/archives/javamail_on_jdk8_ssl_problem.html" title="Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案">Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案</a> (0)</li><li><a href="http://terence2008.info/archives/i-expect.html" title="我期待……">我期待……</a> (2)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/backup-database-webroot.html" title="定时备份mysql和网站目录文件">定时备份mysql和网站目录文件</a> (0)</li><li><a href="http://terence2008.info/archives/my-plugins.html" title="我正在使用的插件列表">我正在使用的插件列表</a> (1)</li><li><a href="http://terence2008.info/archives/how_to_connect_eap_wifi.html" title="如何手动连接802.1x EAP证书加密WIFI">如何手动连接802.1x EAP证书加密WIFI</a> (1)</li><li><a href="http://terence2008.info/archives/013.html" title="Google阅读器里RSS的显示问题">Google阅读器里RSS的显示问题</a> (0)</li><li><a href="http://terence2008.info/archives/006.html" title="电子杂志《物华特刊》发布！">电子杂志《物华特刊》发布！</a> (2)</li><li><a href="http://terence2008.info/archives/google-adsense.html" title="巧用Google AdSense赚美元">巧用Google AdSense赚美元</a> (1)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/chrome_firefox_earliest_release.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>解决Gnome面板通知栏里没有Network Manager图标问题</title>
		<link>http://terence2008.info/archives/network_manager_icon.html</link>
		<comments>http://terence2008.info/archives/network_manager_icon.html#comments</comments>
		<pubDate>Fri, 24 Jan 2014 09:16:17 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[Gnome]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=463</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 本人的测试服务器安装的是CentOS 6.x，如果用非root用户登录到<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/gnome" title="查看 Gnome 的全部文章">Gnome</a></span>桌面时，Network Manager图标就不会出现在面板通知栏里，虽然可以用命令行来管理网络的开关，但既然是图形化操作界面，不能用鼠标点点就能控制网络的话，总觉得是不完美的。对于这个问题其实我很早就发现了，但一直没去研究，今天下决心来解决下这个遗难杂症。</p>
<p>&nbsp; &nbsp; &nbsp; 首先Google，发现遇到这个问题的人还是挺多的，给出的解决方案也无非就是检查NetworkManager服务有没有启动，再者就是重置面板，恢复默认设置，但都不能解决问题。然后在一个国外<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/linux" title="查看 Linux 的全部文章">Linux</a></span>论坛里获得了启发，<a href="http://www.linuxquestions.org/questions/arch-29/networkmanager-857362/" target="_blank">链接在此</a>。</p>
<p>&nbsp; &nbsp; &nbsp; 回头总结了下原因，其实问题出在nm-applet上，Network Manager的面板图标是由该命令启动的，在命令行下运行该命令后出现了以下错误（非sudo）：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>terence<span style="color: #000000; font-weight: bold;">@</span>centos system.d<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ nm-applet
&nbsp;
<span style="color: #000000; font-weight: bold;">**</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>nm-applet:<span style="color: #000000;">4290</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>: WARNING <span style="color: #000000; font-weight: bold;">**</span>:   request_name<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>: Could not acquire the NetworkManagerUserSettings service.
  Error: <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">9</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> Connection <span style="color: #ff0000;">&quot;:1.172&quot;</span> is not allowed to own the service <span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerUserSettings&quot;</span> due to security policies <span style="color: #000000; font-weight: bold;">in</span> the configuration <span style="color: #c20cb9; font-weight: bold;">file</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 怪不得没法出现在面板上，如果采用sudo启动的话就能出现图标了，看字面意思应该是受到了安全策略的限制导致了启动失败。解决方案很简单，只要修改相应的配置就可以了。</p>
<p>&nbsp; &nbsp; &nbsp; 打开/etc/dbus-1/system.d/NetworkManager.conf，找到&lt;policy user="root"&gt;节点，然后复制和它一样的一个节点在其下面，修改节点的user属性为你当前登陆的用户名：</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;policy</span> <span style="color: #000066;">user</span>=<span style="color: #ff0000;">&quot;root&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">own</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">own</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerSystemSettings&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerSystemSettings&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">send_interface</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager.PPP&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/policy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;policy</span> <span style="color: #000066;">user</span>=<span style="color: #ff0000;">&quot;terence&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">own</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">own</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerSystemSettings&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerSystemSettings&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">send_interface</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager.PPP&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/policy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 相应的/etc/dbus-1/system.d/nm-applet.conf，也是找到&lt;policy user="root"&gt;节点，然后复制和它一样的一个节点在其下面，修改节点的user属性为你当前登陆的用户名：</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;policy</span> <span style="color: #000066;">user</span>=<span style="color: #ff0000;">&quot;root&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">own</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerUserSettings&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerUserSettings&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">send_interface</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerSettings&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerUserSettings&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">send_interface</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerSettings.Connection&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerUserSettings&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">send_interface</span>=<span style="color: #ff0000;">&quot;org.freedesktop.DBus.Properties&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Only root can get secrets --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerUserSettings&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">send_interface</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerSettings.Connection.Secrets&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/policy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;policy</span> <span style="color: #000066;">user</span>=<span style="color: #ff0000;">&quot;terence&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">own</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerUserSettings&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerUserSettings&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">send_interface</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerSettings&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerUserSettings&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">send_interface</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerSettings.Connection&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerUserSettings&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">send_interface</span>=<span style="color: #ff0000;">&quot;org.freedesktop.DBus.Properties&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
        <span style="color: #808080; font-style: italic;">&lt;!-- Only root can get secrets --&gt;</span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerUserSettings&quot;</span></span>
<span style="color: #009900;">               <span style="color: #000066;">send_interface</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManagerSettings.Connection.Secrets&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/policy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 修改完配置文件后重启<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/gnome" title="查看 Gnome 的全部文章">Gnome</a></span>桌面就生效了，这下Network Manager图标看你往哪儿跑！当然如果真的是手贱活生生把图标给弄没的话，那就试试重置面板大法吧：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">gconftool-<span style="color: #000000;">2</span> <span style="color: #660033;">--recursive-unset</span> <span style="color: #000000; font-weight: bold;">/</span>apps<span style="color: #000000; font-weight: bold;">/</span>panel</pre></div></div>

<p><a href="http://terence2008.info/wp-content/uploads/2014/01/NetworkManagerIcon.png" rel="lightbox[463]" title="NetworkManagerIcon"><img class="alignnone size-medium wp-image-464" title="NetworkManagerIcon" src="http://terence2008.info/wp-content/uploads/2014/01/NetworkManagerIcon-300x145.png" alt="" width="300" height="145" /></a></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="解决Gnome面板通知栏里没有Network Manager图标问题" href="http://terence2008.info/archives/network_manager_icon.html">《解决Gnome面板通知栏里没有Network Manager图标问题》</a></div></blockquote><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/how_to_connect_eap_wifi.html" title="如何手动连接802.1x EAP证书加密WIFI">如何手动连接802.1x EAP证书加密WIFI</a> (1)</li><li><a href="http://terence2008.info/archives/ubuntu-service-autostart.html" title="Ubuntu的两种服务自启动模式">Ubuntu的两种服务自启动模式</a> (0)</li><li><a href="http://terence2008.info/archives/001.html" title="写在最最开始">写在最最开始</a> (4)</li><li><a href="http://terence2008.info/archives/eclipse-optimizing.html" title="Eclipse性能优化实践">Eclipse性能优化实践</a> (0)</li><li><a href="http://terence2008.info/archives/003.html" title="推荐一个博客">推荐一个博客</a> (0)</li><li><a href="http://terence2008.info/archives/013.html" title="Google阅读器里RSS的显示问题">Google阅读器里RSS的显示问题</a> (0)</li><li><a href="http://terence2008.info/archives/wordpress_database_optimize.html" title="WordPress数据库的一处性能优化">WordPress数据库的一处性能优化</a> (1)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/hibernate_criteria_order.html" title="Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作">Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作</a> (2)</li><li><a href="http://terence2008.info/archives/009.html" title="让flash植入代码符合xhtml标准">让flash植入代码符合xhtml标准</a> (1)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/network_manager_icon.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>随便分析下1月21日网络大规模故障的事故原因</title>
		<link>http://terence2008.info/archives/network_error_analysis.html</link>
		<comments>http://terence2008.info/archives/network_error_analysis.html#comments</comments>
		<pubDate>Tue, 21 Jan 2014 14:13:11 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[事故]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=458</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp;&nbsp;今天下午的全民网络<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e4%ba%8b%e6%95%85" title="查看 事故 的全部文章">事故</a></span>相信大家都已经在各大网站上看到了吧，15点10分左右，国内访问通用顶级根域名服务器出现异常，都被A解析到了65.49.2.178这个IP上，该A记录的TTL的值为4万多，如果不手动刷新<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/dns" title="查看 DNS 的全部文章">DNS</a></span>缓存的话，理论上最多需要大概12小时才会全部恢复正常。在这期间许多国内所熟知的网站域名都会被尝试打开65.49.2.178的页面，导致正常网页无法打开，具体可以参考<a href="http://tech.qq.com/a/20140121/020318.htm" target="_blank">这个链接</a>。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 造成今天这个重大<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e4%ba%8b%e6%95%85" title="查看 事故 的全部文章">事故</a></span>的原因到现在为止已有不少所谓的专家做了解释，但仔细一想又觉得哪儿有问题，所以自己瞎猜了个结论：可能“功夫网”某操作员的乌龙指。原因如下：</p>
<p>1. 我国境内<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/dns" title="查看 DNS 的全部文章">DNS</a></span>根被劫持/污染，被污染网站IP地址指向65.49.2.178，可以使用dig +trace看到。</p>
<p>2. 有能力污染<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/dns" title="查看 DNS 的全部文章">DNS</a></span> root的几乎只可能是GFW。</p>
<p>3. <a href="http://whatismyipaddress.com/ip/65.49.2.178" target="_blank">http://whatismyipaddress.com/ip/65.49.2.178</a> 可以看到Organization: Sophidea。</p>
<p>4. <a href="http://www.markosweb.com/hosting/sophidea/" target="_blank">http://www.markosweb.com/hosting/sophidea/</a> 可以看到这个服务商的最大客户，就是鼎鼎有名的dong tai wang，zi you men的出品方。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 所以不难猜测出过程可能是这样的，某操作员本来要将该IP封禁dong tai wang的IP，从而阻止大家下载zi you men。但是操作失误，错误的使用了劫持功能，并且没有填写要劫持的域名，然后把该IP填写到了劫持后的地址上，然后造成了无法挽回的事故。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 只是几个简单的分析，非常不严谨，请大家看完笑笑就可以了。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="随便分析下1月21日网络大规模故障的事故原因" href="http://terence2008.info/archives/network_error_analysis.html">《随便分析下1月21日网络大规模故障的事故原因》</a></div></blockquote><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/vamt_3_1_independent_version.html" title="VAMT 3.1独立版下载">VAMT 3.1独立版下载</a> (0)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/google-adsense.html" title="巧用Google AdSense赚美元">巧用Google AdSense赚美元</a> (1)</li><li><a href="http://terence2008.info/archives/backup-database-webroot.html" title="定时备份mysql和网站目录文件">定时备份mysql和网站目录文件</a> (0)</li><li><a href="http://terence2008.info/archives/010.html" title="网页中连续字符手动换行的方法">网页中连续字符手动换行的方法</a> (0)</li><li><a href="http://terence2008.info/archives/qqgroup_data_miner.html" title="对QQ群关系数据库的数据挖掘">对QQ群关系数据库的数据挖掘</a> (17)</li><li><a href="http://terence2008.info/archives/001.html" title="写在最最开始">写在最最开始</a> (4)</li><li><a href="http://terence2008.info/archives/kindle3_cross_chaintool.html" title="分享自己做的Kindle3交叉编译工具链">分享自己做的Kindle3交叉编译工具链</a> (1)</li><li><a href="http://terence2008.info/archives/hibernate_criteria_order.html" title="Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作">Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作</a> (2)</li><li><a href="http://terence2008.info/archives/007.html" title="李献计历险记">李献计历险记</a> (1)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/network_error_analysis.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>关于SSL证书与CDN加速的选择</title>
		<link>http://terence2008.info/archives/ssl_cdn_choose.html</link>
		<comments>http://terence2008.info/archives/ssl_cdn_choose.html#comments</comments>
		<pubDate>Sun, 12 Jan 2014 14:53:48 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[服务器运维]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[CDN]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[虚拟主机]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=450</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 一直以为能被各大浏览器所承认的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/ssl" title="查看 SSL 的全部文章">SSL</a></span>证书都是要收费的，最近看到一篇文章谈到了一家证书服务商<a href="https://www.startssl.com" target="_blank">StartSSL</a>。它的根证书能被所有平台的浏览器所承认，在它下面可以免费申请二级<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/ssl" title="查看 SSL 的全部文章">SSL</a></span>证书（Class 1）。不过免费的总是有些限制的：1、只能拥有带一个子域名和其根域名的证书；2、不支持通配符子域名；3、证书有效期为一年，但届时可以续期。当然，等交了59.9刀/2yr升级到Class 2等级证书后就没这些限制了。申请方法见<a href="http://www.freehao123.com/startssl-ssl/" target="_blank">此链接</a>。</p>
<p>&nbsp; &nbsp; &nbsp; 然后我就按教程的方法成功申请到了本博客域名对应的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/ssl" title="查看 SSL 的全部文章">SSL</a></span>证书，其实<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/apache" title="查看 apache 的全部文章">apache</a></span>的配置还算容易，获取完相应的证书文件后，在CentOS上安装mod_ssl模块，配置ssl.conf文件为如下形式即可：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">NameVirtualHost 11.22.33.44:<span style="color: #000000;">443</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>VirtualHost 11.22.33.44:<span style="color: #000000;">443</span><span style="color: #000000; font-weight: bold;">&gt;</span>
    ServerName 11.22.33.44
    <span style="color: #000000; font-weight: bold;">&lt;</span>Location <span style="color: #000000; font-weight: bold;">/&gt;</span>
        Order allow,deny
        Deny from all
    <span style="color: #000000; font-weight: bold;">&lt;/</span>Location<span style="color: #000000; font-weight: bold;">&gt;</span>
    SSLEngine on
    SSLProtocol all <span style="color: #660033;">-SSLv2</span>
    SSLCipherSuite ALL:<span style="color: #000000; font-weight: bold;">!</span>ADH:<span style="color: #000000; font-weight: bold;">!</span>EXPORT:<span style="color: #000000; font-weight: bold;">!</span>SSLv2:RC4+RSA:+HIGH:+MEDIUM
    SSLCertificateFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>ssl.crt
    SSLCertificateKeyFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>ssl.key
    SSLCertificateChainFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>sub.class1.server.ca.pem
    SSLCACertificateFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>ca.pem
<span style="color: #000000; font-weight: bold;">&lt;/</span>VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>VirtualHost 11.22.33.44:<span style="color: #000000;">443</span><span style="color: #000000; font-weight: bold;">&gt;</span>
    ServerName www.terence2008.info
    SSLEngine on
    SSLProtocol all <span style="color: #660033;">-SSLv2</span>
    SSLCipherSuite ALL:<span style="color: #000000; font-weight: bold;">!</span>ADH:<span style="color: #000000; font-weight: bold;">!</span>EXPORT:<span style="color: #000000; font-weight: bold;">!</span>SSLv2:RC4+RSA:+HIGH:+MEDIUM
    SSLCertificateFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>ssl.crt
    SSLCertificateKeyFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>ssl.key
    SSLCertificateChainFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>sub.class1.server.ca.pem
    SSLCACertificateFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>ca.pem
    RewriteEngine on
    RewriteRule ^<span style="color: #7a0874; font-weight: bold;">&#40;</span>.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>$ https:<span style="color: #000000; font-weight: bold;">//</span>terence2008.info<span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #007800;">R</span>=<span style="color: #000000;">301</span>,L<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>VirtualHost 11.22.33.44:<span style="color: #000000;">443</span><span style="color: #000000; font-weight: bold;">&gt;</span>
    DocumentRoot <span style="color: #ff0000;">&quot;/var/www/html&quot;</span>
    ServerName terence2008.info
    SSLEngine on
    SSLProtocol all <span style="color: #660033;">-SSLv2</span>
    SSLCipherSuite ALL:<span style="color: #000000; font-weight: bold;">!</span>ADH:<span style="color: #000000; font-weight: bold;">!</span>EXPORT:<span style="color: #000000; font-weight: bold;">!</span>SSLv2:RC4+RSA:+HIGH:+MEDIUM
    SSLCertificateFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>ssl.crt
    SSLCertificateKeyFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>ssl.key
    SSLCertificateChainFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>sub.class1.server.ca.pem
    SSLCACertificateFile <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>httpd<span style="color: #000000; font-weight: bold;">/</span>ca.pem
<span style="color: #000000; font-weight: bold;">&lt;/</span>VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 可以看到我设置了三个VirtualHost，由于本博客是经过<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/cdn" title="查看 CDN 的全部文章">CDN</a></span>加速的，所以我不想让服务器本身的ip提供Web访问服务，所以和之前的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/apache" title="查看 apache 的全部文章">apache</a></span><span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba" title="查看 虚拟主机 的全部文章">虚拟主机</a></span>配置类似，把ServerName为ip的那个设为全局Deny，这样就只能通过域名访问了，而且这样设置还有一个优点，就是杜绝了第三方域名的恶意A记录绑定。另外，为了SEO上的考虑，我把www的SSL子域名全部301转向到了根域名上。</p>
<p>&nbsp; &nbsp; &nbsp; 关于Apache中多个HTTPS<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba" title="查看 虚拟主机 的全部文章">虚拟主机</a></span>的实现可以参考<a href="http://baggio09robert.blog.163.com/blog/static/31745456201031445731643/" target="_blank">这个链接</a>，我就不再详述。主要的问题就是Apache在单网卡且基于域名的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba" title="查看 虚拟主机 的全部文章">虚拟主机</a></span>配置下只能使用同一个证书，或者说即使有不同的证书，最终使用的都是排在前面的默认的第一个。解决的办法只能是：1、采用多网卡，每块网卡绑定一个证书；2、采用通配符子域名证书（*.domain.com），但限制就是旗下所有的网站都是在同一个域名下；3、采用mod_gnutls模块，达到单一IP为多个域名提供SSL服务的目的，但它用的不是OpenSSL库，取而代之的是GnuTLS库，而且不支持SSL2.0和1.0。另外CentOS官方源没有这个模块安装包，具体说明以及安装方法可以参考<a href="https://mod.gnutls.org/" target="_blank">这个链接</a>，我猜测大名鼎鼎的cPanel之所以能做到让用户随意绑定域名和配置其对应的SSL证书，八成也是用了这个模块的缘故吧。</p>
<p>&nbsp; &nbsp; &nbsp; 搞定了SSL，接下来就是<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/cdn" title="查看 CDN 的全部文章">CDN</a></span>了，其实之前没搞过还不知道，原来绝大多数的CDN服务商是不提供SSL加速服务的，可能是由于成本上的考虑吧，据说需要硬件上的支持。目前在网上转了一大圈发现免费支持SSL加速的也就Google的PageSpeed了，真是业界良心啊，<a href="https://developers.google.com/speed/pagespeed/service" target="_blank">链接在此</a>，但仔细一瞧发现它的要求是必须要带子域名，像我的域名是不带www就杯具了，而且还有一个关键的因素，它的加速点没有一个是设立在中国大陆内的，所以对于一个国内博客来说等于没用啊。还有一个国内的CDN服务商是安全宝，是创新工场扶直出来的一个创业小团队，号称支持SSL加速，结果我过去一看，好家伙，需要额外定制，而且费用不菲，<a href="http://www.anquanbao.com/prices" target="_blank">链接在此</a>，最讨厌把收费项目当作广告噱头了。</p>
<p>&nbsp; &nbsp; &nbsp; 搞了半天原来发现对于一个小穷站长来说，SSL和CDN是鱼与熊掌不可兼得的啊。。否则本来我还打算在启用CDN加速的情况下，博客前台HTTP和HTTPS能同时访问，后台强制使用HTTPS呢，设置方法<a href="http://m114.org/https-for-wordpress-admin-and-login/" target="_blank">见此链接</a>。也罢也罢，通过这次学习好歹基本上了解了HTTPS的工作原理，SSL我看还是放弃吧 <img src='https://terence2008.info/wp-includes/images/smilies/icon_neutral.gif' alt=':|' class='wp-smiley' />  </p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="关于SSL证书与CDN加速的选择" href="http://terence2008.info/archives/ssl_cdn_choose.html">《关于SSL证书与CDN加速的选择》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/i-am-back.html" title="时隔三年我又回来啦">时隔三年我又回来啦</a> (2)</li><li><a href="http://terence2008.info/archives/change-space.html" title="换空间了">换空间了</a> (1)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/ssl_cdn_choose.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unicode编码在线转换工具</title>
		<link>http://terence2008.info/archives/unicode_encoding_conversion.html</link>
		<comments>http://terence2008.info/archives/unicode_encoding_conversion.html#comments</comments>
		<pubDate>Sun, 22 Dec 2013 15:58:27 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[Unicode]]></category>
		<category><![CDATA[工具]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=428</guid>
		<description><![CDATA[<p><strong>什么是<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/unicode" title="查看 Unicode 的全部文章">Unicode</a></span>编码</strong></p>
<p>&nbsp; &nbsp; &nbsp; <span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/unicode" title="查看 Unicode 的全部文章">Unicode</a></span>是目前用来解决ASCII码256个字符限制问题的一种比较流行的解决方案。大家知道，ASCII字符集只有256个字符，用0-255之间的数字来表示。包括大小写字母、数字以及少数特殊字符；如标点符号、货币符号等。对于大多数拉丁语言来说，这些字符已经够用。但是，许多亚洲和东方语言所用的字符远远不止256个字符。人们为了突破ASCII码字符数的限制，试图用一种简单的方法来针对超过256个字符的语言编写计算机程序。于是 Unicode应运而生。Unicode通过用双字节来表示一个字符，从而在更大范围内将数字代码映射到多种语言的字符集。 Unicode给每个字符提供了一个唯一的数字，不论是什么平台，不论是什么程序，不论什么语言。Unicode标准已经被这些工业界的领导者们所采用，最新的标准都需要Unicode，例如XML,Java,ECMAScript(JavaScript),LDAP,CORBA 3.0,WML等等，并且，Unicode是实现ISO/IEC 10646的正规方式。许多操作系统，所有最新的浏览器和许多其他产品都支持它。Unicode标准的出现和支持它<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e5%b7%a5%e5%85%b7" title="查看 工具 的全部文章">工具</a></span>的存在，是近来全球软件技术最重要的发展趋势。</p>
<p><strong>为什么使用Unicode</strong></p>
<p>&nbsp; &nbsp; &nbsp; 基本上，计算机只是处理数字。它们指定一个数字来储存字母或其他字符。在创造Unicode之前，有数百种指定这些数字的编码系统。没有一个编码可以包含足够的字符。例如单单欧洲就需要好几种不同的编码来包括所有的语言。即使是单一种语言，例如英语，也没有哪一个编码可以适用于所有的字母，标点符号，和常用的技术符号。这些编码系统也会互相冲突。也就是说两种编码可能使用相同的数字代表两个不同的字符，或使用不同的数字代表相同的字符。任何一台特定的计算机都需要支持许多不同的编码，但是不论什么时候数据通过不同的编码或平台之间，那些数据总会有损坏的危险。 比如简体中文（GB）、繁体中文（BIG5）、日文中，“赵”都是一个字，但是编码不同。在不同的编码下，BIG5的“赵”是0xBBAF，而0xBBAF在GB里面就被显示为“化”，这就是乱码。而Unicode采用统一的编码，“赵”只有一个，不必管他在哪种文字里。</p>
<p><strong>Unicode编码在线转换<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e5%b7%a5%e5%85%b7" title="查看 工具 的全部文章">工具</a></span></strong></p>
<p>&nbsp; &nbsp; &nbsp; 由于网页中的字符为了避免乱码，故会把非ASCII字符转换为Unicode格式，例如“赵”的Unicode格式为\u8d75，但这样做的话就不会非常的不直观。所以下面提供了一个Unicode和原始文字互转的工具。</p>
<form action="">
<p>
<script type="text/javascript">
var decToHex = function(str) {
    var res=[];
    for(var i=0;i<str.length;i++)
        res[i]=("00"+str.charCodeAt(i).toString(16)).slice(-4);
    return "\\u"+res.join("\\u");
}
var hexToDec = function(str) {
    str=str.replace(/\\/g,"%");
    return unescape(str);
}
var bianma=function()
{
document.getElementById('code12').value=decToHex(document.getElementById('code11').value);
}
var jiema=function()
{
document.getElementById('code22').value=hexToDec(document.getElementById('code21').value);
}
</script>
</p>
<p><textarea id="code11" style="width: 422px; height: 136px;" cols="50" rows="5"></textarea></p>
<input onclick="bianma()" type="button" value="编码" />
<p><textarea id="code12" style="width: 422px; height: 136px;" cols="50" rows="5"></textarea></p>
<p>&nbsp;</p>
<p><textarea id="code21" style="width: 422px; height: 136px;" cols="50" rows="5"></textarea></p>
<input onclick="jiema()" type="button" value="解码" />
<p><textarea id="code22" style="width: 422px; height: 136px;" cols="50" rows="5"></textarea></p>
</form>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="Unicode编码在线转换工具" href="http://terence2008.info/archives/unicode_encoding_conversion.html">《Unicode编码在线转换工具》</a></div></blockquote><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/009.html" title="让flash植入代码符合xhtml标准">让flash植入代码符合xhtml标准</a> (1)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/i-am-back.html" title="时隔三年我又回来啦">时隔三年我又回来啦</a> (2)</li><li><a href="http://terence2008.info/archives/thesis.html" title="浅谈不同浏览器地址栏中编码的差异">浅谈不同浏览器地址栏中编码的差异</a> (2)</li><li><a href="http://terence2008.info/archives/finding_compare.html" title="六种查找算法效率比较">六种查找算法效率比较</a> (8)</li><li><a href="http://terence2008.info/archives/a-song.html" title="一首歌 两个人">一首歌 两个人</a> (0)</li><li><a href="http://terence2008.info/archives/ajaxswing.html" title="AjaxSwing4.4.0授权码">AjaxSwing4.4.0授权码</a> (2)</li><li><a href="http://terence2008.info/archives/google-adsense.html" title="巧用Google AdSense赚美元">巧用Google AdSense赚美元</a> (1)</li><li><a href="http://terence2008.info/archives/007.html" title="李献计历险记">李献计历险记</a> (1)</li><li><a href="http://terence2008.info/archives/008.html" title="信春哥 死后四次原地满血复活">信春哥 死后四次原地满血复活</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/unicode_encoding_conversion.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>对QQ群关系数据库的数据挖掘</title>
		<link>http://terence2008.info/archives/qqgroup_data_miner.html</link>
		<comments>http://terence2008.info/archives/qqgroup_data_miner.html#comments</comments>
		<pubDate>Wed, 11 Dec 2013 11:47:00 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[QQ]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[数据挖掘]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=414</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 首先声明一点，本人的目的并非是为了去窥探别人的隐私而去做这件事情，而是纯粹以一个<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%95%b0%e6%8d%ae%e6%8c%96%e6%8e%98" title="查看 数据挖掘 的全部文章">数据挖掘</a></span>的角度来看待它。<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/qq" title="查看 QQ 的全部文章">QQ</a></span>群关系数据库已经在上个月也就是11月18日被好事者公布在了网络上，立马遭到了网友的疯转，乌云-漏洞报告平台也在第一时间公布了这个漏洞消息。</p>
<p>&nbsp; &nbsp; &nbsp; 该<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/qq" title="查看 QQ 的全部文章">QQ</a></span>群数据库其实是2011年11月的时候被黑客从一个腾讯漏洞网站上脱裤下来的，里面包含了当时所有<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/qq" title="查看 QQ 的全部文章">QQ</a></span>号的基本个人信息与所加入群的对应关系以及群的一些基本信息，解压出来后数据库总大小超过了90G，用的是<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/sql" title="查看 SQL 的全部文章">SQL</a></span> Server 2000，以数据分片的形式存储，共有22个库。虽然其中并不包含密码信息，但可以从这里获得某个QQ号的昵称、年龄、性别和所加入的群的号码和群名称等信息。要知道许多人在加入某些重要群的时候所修改的昵称会是自己的真实姓名，所以无意中会使自己的QQ实名化，然后通过分析所加入的群名称，就基本上能判断该用户的读书工作经历乃至整个关系网了，因为毕竟我们当中的大多数已经越来越离不开QQ，生活中的点点滴滴都有可能有意无意的和QQ扯上了些关系。</p>
<p>&nbsp; &nbsp; &nbsp; 就像网上所说的，为什么11年的数据库到了现在才被公布出来，说明那些第一时间获得数据的黑客已经对数据进行了价值利用，直到利用完后才把它随便扔到了网络上，对于这个观点，我表示同意，可见这次的泄露事件影响有多么的可怕。</p>
<p>&nbsp; &nbsp; &nbsp; 撇开数据泄漏不说，我们把目光转回这个90个G的庞大数据库上，既然木已成舟，对于我们这些后知后觉的人来说，这么多的数据正好可以作为<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%95%b0%e6%8d%ae%e6%8c%96%e6%8e%98" title="查看 数据挖掘 的全部文章">数据挖掘</a></span>的练手好机会，虽然有悖道义，但只要本着求是的态度，只用于研究，所以在这里，我保证不会公布任何和个人信息有关的数据。</p>
<p>&nbsp; &nbsp; &nbsp; 其实对于这个QQ群数据库能挖掘的数据形式并不多，22个库归结下来就两种表：Group表和QunList表。Group表包含了QQ号的个人基本信息和对应加入的QQ群号，QunList表则包含了群的一些基本信息，这两张表都是以群号的递增顺序排列的，Group表共1100张，QunList表共110张，各自平均分散在11个数据库里，共22个数据库。其中Group表并没有被完全填充，Group1是空表，Group970以后的大部分表也是空的，然后QunList表中的群号比Group表中的要多，我猜测可能这两种表并不是在同一时间被脱裤的。以下是表结构：</p>
<p>Group表</p>
<p><a href="http://terence2008.info/wp-content/uploads/2013/12/group_table.jpg" rel="lightbox[414]" title="Group表"><img class="size-medium wp-image-420 alignnone" title="Group表" src="http://terence2008.info/wp-content/uploads/2013/12/group_table-300x133.jpg" alt="" width="300" height="133" /></a></p>
<p>QunList表</p>
<p><a href="http://terence2008.info/wp-content/uploads/2013/12/qunlist_table.jpg" rel="lightbox[414]" title="QunList表"><img class="alignnone size-medium wp-image-421" title="QunList表" src="http://terence2008.info/wp-content/uploads/2013/12/qunlist_table-300x133.jpg" alt="" width="300" height="133" /></a></p>
<p>&nbsp; &nbsp; &nbsp; 随后的思路就比较简单了，我查询一个QQ号，然后从所有的Group表中进行查询遍历，再是把查询到的群号分别在对应的QunList表中查询，以获得群名称，以下是自己设计的查询结果表：</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #66cc66;">&#91;</span>dbo<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>QQNumInfo<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #66cc66;">&#91;</span>ID<span style="color: #66cc66;">&#93;</span> int <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> IDENTITY<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">,</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#91;</span>QQNum<span style="color: #66cc66;">&#93;</span> int <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#91;</span>Nick<span style="color: #66cc66;">&#93;</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">20</span><span style="color: #66cc66;">&#41;</span> COLLATE Chinese_PRC_CI_AS <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#91;</span>Age<span style="color: #66cc66;">&#93;</span> int <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#91;</span>Gender<span style="color: #66cc66;">&#93;</span> int <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#91;</span>QunNum<span style="color: #66cc66;">&#93;</span> int <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#91;</span>QunTitle<span style="color: #66cc66;">&#93;</span> varchar<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">22</span><span style="color: #66cc66;">&#41;</span> COLLATE Chinese_PRC_CI_AS <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">&#91;</span>NotExist<span style="color: #66cc66;">&#93;</span> char<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> COLLATE Chinese_PRC_CI_AS <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>
CONSTRAINT <span style="color: #66cc66;">&#91;</span>PK_QQInfo<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>ID<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">PRIMARY</span><span style="color: #66cc66;">&#93;</span>
GO
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #66cc66;">&#91;</span>INDEX_QQNum<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#91;</span>dbo<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>QQNumInfo<span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>QQNum<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">ASC</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">PRIMARY</span><span style="color: #66cc66;">&#93;</span>
GO
&nbsp;
<span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">INDEX</span> <span style="color: #66cc66;">&#91;</span>INDEX_QunNum<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#91;</span>dbo<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">.</span><span style="color: #66cc66;">&#91;</span>QQNumInfo<span style="color: #66cc66;">&#93;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>QunNum<span style="color: #66cc66;">&#93;</span> <span style="color: #993333; font-weight: bold;">ASC</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #993333; font-weight: bold;">ON</span> <span style="color: #66cc66;">&#91;</span><span style="color: #993333; font-weight: bold;">PRIMARY</span><span style="color: #66cc66;">&#93;</span>
GO</pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 整个查询逻辑采用存储过程语言t-sql来写，传入QQNum这个参数，首先查找结果表中是否存在记录，如果有则直接返回结果集，NotExist列是用来标记经过查找后返回为空集的QQ号，以便在下次查找的时候能立即返回为空；如果QQ号在结果表中不存在，则进入一系列的查询逻辑并最终将结果存入结果表中并返回结果集。以下是存储过程代码：</p>

<div class="wp_syntax"><div class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">ALTER</span> <span style="color: #0000FF;">PROCEDURE</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>LookupQQNum<span style="color: #808080;">&#93;</span> @QQ <span style="color: #0000FF;">INT</span>
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
	<span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span> <span style="color: #008080;">--防止在jdbc里无法返回结果集</span>
	<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">TABLE</span> #tmp <span style="color: #808080;">&#40;</span>
		<span style="color: #808080;">&#91;</span>ID<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> <span style="color: #0000FF;">IDENTITY</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span>,<span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> ,
		<span style="color: #808080;">&#91;</span>QQNum<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span> <span style="color: #808080;">NOT</span> <span style="color: #808080;">NULL</span> ,
		<span style="color: #808080;">&#91;</span>Nick<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">20</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">COLLATE</span> Chinese_PRC_CI_AS <span style="color: #808080;">NULL</span> ,
		<span style="color: #808080;">&#91;</span>Age<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span> <span style="color: #808080;">NULL</span> ,
		<span style="color: #808080;">&#91;</span>Gender<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span> <span style="color: #808080;">NULL</span> ,
		<span style="color: #808080;">&#91;</span>QunNum<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">INT</span> <span style="color: #808080;">NULL</span> ,
		<span style="color: #808080;">&#91;</span>QunTitle<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">22</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">COLLATE</span> Chinese_PRC_CI_AS <span style="color: #808080;">NULL</span> ,
		<span style="color: #808080;">&#91;</span>NotExist<span style="color: #808080;">&#93;</span> <span style="color: #0000FF;">CHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">COLLATE</span> Chinese_PRC_CI_AS <span style="color: #808080;">NULL</span>
	<span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #tmp <span style="color: #0000FF;">SELECT</span> QQNum,Nick,Age,Gender,QunNum,QunTitle,NotExist <span style="color: #0000FF;">FROM</span> QQNumInfo <span style="color: #0000FF;">WHERE</span> QQNum<span style="color: #808080;">=</span>@QQ
	<span style="color: #0000FF;">IF</span> exists<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> QQNum <span style="color: #0000FF;">FROM</span> #tmp<span style="color: #808080;">&#41;</span>
	<span style="color: #0000FF;">BEGIN</span>
		<span style="color: #0000FF;">DECLARE</span> @IsNotExist <span style="color: #0000FF;">CHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span>
		<span style="color: #0000FF;">SELECT</span> <span style="color: #0000FF;">TOP</span> <span style="color: #000;">1</span> @IsNotExist<span style="color: #808080;">=</span>NotExist <span style="color: #0000FF;">FROM</span> #tmp
		<span style="color: #0000FF;">IF</span> @IsNotExist <span style="color: #0000FF;">IS</span> null
			<span style="color: #0000FF;">SELECT</span> ID,QQNum,Nick,Age,Gender,QunNum,QunTitle <span style="color: #0000FF;">FROM</span> #tmp
		<span style="color: #0000FF;">ELSE</span>
			<span style="color: #0000FF;">SELECT</span> ID,QQNum,NotExist <span style="color: #0000FF;">FROM</span> #tmp
	<span style="color: #0000FF;">END</span>
	<span style="color: #0000FF;">ELSE</span>
	<span style="color: #0000FF;">BEGIN</span>
		<span style="color: #0000FF;">DECLARE</span> @table_num <span style="color: #0000FF;">INT</span>
		<span style="color: #0000FF;">DECLARE</span> @database_num <span style="color: #0000FF;">INT</span>
		<span style="color: #0000FF;">SET</span> @table_num<span style="color: #808080;">=</span><span style="color: #000;">2</span>
		<span style="color: #0000FF;">WHILE</span> @table_num<span style="color: #808080;">&lt;=</span><span style="color: #000;">970</span>
		<span style="color: #0000FF;">BEGIN</span>
			<span style="color: #0000FF;">SET</span> @database_num<span style="color: #808080;">=</span><span style="color: #808080;">&#40;</span>@table_num<span style="color: #808080;">-</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">/</span><span style="color: #000;">100</span><span style="color: #808080;">+</span><span style="color: #000;">1</span>
			<span style="color: #0000FF;">EXEC</span> <span style="color: #808080;">&#40;</span>
				<span style="color: #FF0000;">'insert into #tmp(QQNum,Nick,Age,Gender,QunNum) select QQNum,Nick,Age,Gender,QunNum from GroupData'</span>
				<span style="color: #808080;">+</span> @database_num <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.dbo.Group'</span> <span style="color: #808080;">+</span> @table_num <span style="color: #808080;">+</span> <span style="color: #FF0000;">' where QQNum='</span> <span style="color: #808080;">+</span> @QQ
			<span style="color: #808080;">&#41;</span>
			<span style="color: #0000FF;">SET</span> @table_num<span style="color: #808080;">=</span>@table_num<span style="color: #808080;">+</span><span style="color: #000;">1</span>
		<span style="color: #0000FF;">END</span>
		<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #tmp<span style="color: #808080;">&#40;</span>QQNum,Nick,Age,Gender,QunNum<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">SELECT</span> QQNum,Nick,Age,Gender,QunNum <span style="color: #0000FF;">FROM</span> GroupData11.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">Group1001</span> <span style="color: #0000FF;">WHERE</span> QQNum<span style="color: #808080;">=</span>@QQ
		<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #tmp<span style="color: #808080;">&#40;</span>QQNum,Nick,Age,Gender,QunNum<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">SELECT</span> QQNum,Nick,Age,Gender,QunNum <span style="color: #0000FF;">FROM</span> GroupData11.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">Group1002</span> <span style="color: #0000FF;">WHERE</span> QQNum<span style="color: #808080;">=</span>@QQ
		<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #tmp<span style="color: #808080;">&#40;</span>QQNum,Nick,Age,Gender,QunNum<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">SELECT</span> QQNum,Nick,Age,Gender,QunNum <span style="color: #0000FF;">FROM</span> GroupData11.<span style="color: #202020;">dbo</span>.<span style="color: #202020;">Group1003</span> <span style="color: #0000FF;">WHERE</span> QQNum<span style="color: #808080;">=</span>@QQ
		<span style="color: #0000FF;">IF</span> not exists<span style="color: #808080;">&#40;</span><span style="color: #0000FF;">SELECT</span> QQNum <span style="color: #0000FF;">FROM</span> #tmp<span style="color: #808080;">&#41;</span>
		<span style="color: #0000FF;">BEGIN</span>
			<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> #tmp<span style="color: #808080;">&#40;</span>QQNum,NotExist<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span>@QQ,<span style="color: #FF0000;">'1'</span><span style="color: #808080;">&#41;</span>
			<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> QQNumInfo<span style="color: #808080;">&#40;</span>QQNum,NotExist<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span>@QQ,<span style="color: #FF0000;">'1'</span><span style="color: #808080;">&#41;</span>
			<span style="color: #0000FF;">SELECT</span> ID,QQNum,NotExist <span style="color: #0000FF;">FROM</span> #tmp
		<span style="color: #0000FF;">END</span>
		<span style="color: #0000FF;">ELSE</span>
		<span style="color: #0000FF;">BEGIN</span>
			<span style="color: #0000FF;">DECLARE</span> cursor_QunNum <span style="color: #0000FF;">CURSOR</span> <span style="color: #0000FF;">FOR</span> <span style="color: #0000FF;">SELECT</span> QunNum <span style="color: #0000FF;">FROM</span> #tmp
			<span style="color: #0000FF;">DECLARE</span> @temp <span style="color: #0000FF;">INT</span>
			<span style="color: #0000FF;">DECLARE</span> @QunList_Num <span style="color: #0000FF;">INT</span>
			<span style="color: #0000FF;">DECLARE</span> @QunInfo_Num <span style="color: #0000FF;">INT</span>
			<span style="color: #0000FF;">OPEN</span> cursor_QunNum
			<span style="color: #0000FF;">FETCH</span> <span style="color: #0000FF;">NEXT</span> <span style="color: #0000FF;">FROM</span> cursor_QunNum <span style="color: #0000FF;">INTO</span> @temp
			<span style="color: #0000FF;">WHILE</span> <span style="color: #FF00FF;">@@FETCH_STATUS</span><span style="color: #808080;">=</span><span style="color: #000;">0</span>
			<span style="color: #0000FF;">BEGIN</span>
				<span style="color: #0000FF;">SET</span> @QunList_Num<span style="color: #808080;">=</span><span style="color: #808080;">&#40;</span>@temp<span style="color: #808080;">-</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">/</span><span style="color: #000;">1000000</span><span style="color: #808080;">+</span><span style="color: #000;">1</span>
				<span style="color: #0000FF;">SET</span> @QunInfo_Num<span style="color: #808080;">=</span><span style="color: #808080;">&#40;</span>@QunList_Num<span style="color: #808080;">-</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span><span style="color: #808080;">/</span><span style="color: #000;">10</span><span style="color: #808080;">+</span><span style="color: #000;">1</span>
				<span style="color: #0000FF;">EXEC</span> <span style="color: #808080;">&#40;</span>
					<span style="color: #FF0000;">'update #tmp set QunTitle=(select Title from QunInfo'</span> <span style="color: #808080;">+</span> @QunInfo_Num <span style="color: #808080;">+</span> <span style="color: #FF0000;">'.dbo.QunList'</span>
					<span style="color: #808080;">+</span> @QunList_Num <span style="color: #808080;">+</span> <span style="color: #FF0000;">' where QunNum='</span> <span style="color: #808080;">+</span> @temp <span style="color: #808080;">+</span> <span style="color: #FF0000;">') where QunNum='</span> <span style="color: #808080;">+</span> @temp
				<span style="color: #808080;">&#41;</span>
				<span style="color: #0000FF;">FETCH</span> <span style="color: #0000FF;">NEXT</span> <span style="color: #0000FF;">FROM</span> cursor_QunNum <span style="color: #0000FF;">INTO</span> @temp
			<span style="color: #0000FF;">END</span>
			<span style="color: #0000FF;">CLOSE</span> cursor_QunNum
			<span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> QQNumInfo<span style="color: #808080;">&#40;</span>QQNum,Nick,Age,Gender,QunNum,QunTitle<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">SELECT</span> QQNum,Nick,Age,Gender,QunNum,QunTitle <span style="color: #0000FF;">FROM</span> #tmp
			<span style="color: #0000FF;">SELECT</span> ID,QQNum,Nick,Age,Gender,QunNum,QunTitle <span style="color: #0000FF;">FROM</span> #tmp
		<span style="color: #0000FF;">END</span>
	<span style="color: #0000FF;">END</span>
<span style="color: #0000FF;">END</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 存储过程代码量不多，就70行的样子，但毕竟面对的是90个G的海量数据，经过几次测试发现查询一个QQ号平均耗时29分钟，我的测试机配置是台式一代i3双核超线程CPU+2G内存+500G SATA2硬盘，采用的数据库是<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/sql" title="查看 SQL 的全部文章">SQL</a></span> Server 2008 R2 SP2。所以也只能作为测试用途，这么长的查询时间是谁也受不了的 <img src='https://terence2008.info/wp-includes/images/smilies/icon_razz.gif' alt=':razz:' class='wp-smiley' /> </p>
<p>&nbsp; &nbsp; &nbsp; 最后上一张查询结果返回集合的截图吧，当然是经过打码的：</p>
<p><a href="http://terence2008.info/wp-content/uploads/2013/12/qqnuminfo_table.jpg" rel="lightbox[414]" title="QQNumInfo表"><img class="alignnone size-medium wp-image-423" title="QQNumInfo表" src="http://terence2008.info/wp-content/uploads/2013/12/qqnuminfo_table-300x168.jpg" alt="" width="300" height="168" /></a></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="对QQ群关系数据库的数据挖掘" href="http://terence2008.info/archives/qqgroup_data_miner.html">《对QQ群关系数据库的数据挖掘》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/wordpress_database_optimize.html" title="WordPress数据库的一处性能优化">WordPress数据库的一处性能优化</a> (1)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/qqgroup_data_miner.html/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Eclipse性能优化实践</title>
		<link>http://terence2008.info/archives/eclipse-optimizing.html</link>
		<comments>http://terence2008.info/archives/eclipse-optimizing.html#comments</comments>
		<pubDate>Fri, 29 Nov 2013 13:19:00 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[性能优化]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=407</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 这几天毕设开题搞定，空下来看了《深入理解<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/java" title="查看 Java 的全部文章">Java</a></span>虚拟机——JVM高级特性与最佳实践》一书，收益良多，平时经常用<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/java" title="查看 Java 的全部文章">Java</a></span>，但其最本质的运行原理却一直是一知半解，比如堆与非堆内存、新生代年老代与永久代的垃圾回收处理机制、class文件的内部结构等等都是我所感兴趣的内容。</p>
<p>&nbsp; &nbsp; &nbsp; 说到Java的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96" title="查看 性能优化 的全部文章">性能优化</a></span>实践，这本书里也就理所当然的提到了<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/eclipse" title="查看 Eclipse 的全部文章">Eclipse</a></span>的优化，之前我也清楚只要修改eclipse.ini文件里的相关配置选项后，打开速度和运行效率会有很大的提高，网上也有很多类似的优化建议，但都不是很全面，或者没有解释清楚。通过阅读本书后，我总算对每个配置选项都有了深入的认识，并最终整理了一份适合大多数情况下的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/eclipse" title="查看 Eclipse 的全部文章">Eclipse</a></span><span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96" title="查看 性能优化 的全部文章">性能优化</a></span>配置清单。当然应用以后效果也是非常显著的，特别是<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/eclipse" title="查看 Eclipse 的全部文章">Eclipse</a></span>冷启动时不会再界面假死了，全程都有比较良好的用户体验和性能表现。因为我的eclipse里加载了不少插件，其中也包含了像MyEclipse这样的大型插件，所以通过优化后启动时间有了明显的缩短。</p>
<p>&nbsp; &nbsp; &nbsp; 下面就贴出我参考本书后整理出来的eclipse.ini文件配置清单：</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.1.2.R36x_v20101222
-showsplash
org.eclipse.platform
--launcher.defaultAction
openFile
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
-startup
plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar
-vmargs
-Dosgi.requiredJavaVersion<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">1.5</span>
-Xms768m
-Xmx768m
-XX:PermSize<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">384m</span>
-XX:MaxPermSize<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">384m</span>
-Xmn128m
-Xverify:none
-Xnoclassgc
-XX:+UseParNewGC
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">85</span>
-XX:ReservedCodeCacheSize<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">64m</span>
-Duser.timezone<span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">GMT+08</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 然后对上面的配置选项做个解释：</p>
<p><strong>关于被删掉的--launcher.XXMaxPermSize</strong></p>
<p>在初始配置文件中，会有两处该选项，对应的值是256M，其实这和下面的-XX:MaxPermSize是一个意思，都是定义了永久代的最大容量，所以我们可以把自带的那两行删掉。之所以Eclipse这么写是因为考虑到了非Sun公司的的虚拟机，当launcher——Windows下的可执行程序eclipse.exe检测到是Eclipse运行在Sun公司的虚拟机上的话，就会把参数值转化为-XX:MaxPermSize传递给虚拟机进程，因为三大商用虚拟机中只有Sun系列的虚拟机才有永久代的概念，即只有HotSpot虚拟机需要设置这个参数，JRockit虚拟机和IBM J9虚拟机都不需要设置。</p>
<p><strong>-Xms与-Xmx</strong></p>
<p>Xms是初始堆大小，Xmx是最大堆大小。JVM中最大堆大小有三方面限制：相关操作系统的数据模型（32-bt还是64-bit）限制；系统的可用虚拟内存限制；系统的可用物理内存限制。32位系统下，一般限制在1.5G~2G；64为操作系统对内存无限制。Xms与Xmx设置为一样以避免内存自动扩展和每次垃圾回收完成后JVM重新分配内存。至于到底分配多少，一般是物理内存的1/4，我的建议是768m基本足够，当然前提是系统有足够的内存。另外需要注意的是Xmx包括了年轻代年老代与永久代，JVM内部管理的非堆内存不算，而且一旦把参数都固定死了的话，虚拟机启动了以后会把设定的内存全部划为私有，别的进程用不了。</p>
<p><strong>-XX:PermSize与-XX:MaxPermSize</strong></p>
<p>刚才提到过，一个是永久代的初始值，一个是永久代的最大值。还是和堆设置一样，初始值和最大值设置为一样，避免内存自动扩展和重新分配。设置为384m较为合适，这是MyEclipse给出的建议值。</p>
<p><strong>-Xmn</strong></p>
<p>新生代的内存值，默认值非常小，运行Eclipse这种大程序经常会以为内存不足而发生频繁的GC，所以把它设为128m。</p>
<p><strong>-Xverify</strong></p>
<p>在进行类加载的时候，字节码验证部分的耗时非常严重，考虑到实际情况：Eclipse使用者甚多，它的编译代码我们认为是可靠的，不需要在加载的时候再进行字节码验证，因此通过此参数禁止字节码验证过程也可作为一项优化措施。</p>
<p><strong>-Xnoclassgc</strong></p>
<p>作用是禁用类垃圾回收，缺省情况下，当一个类没有任何活动实例时，JVM就会从内存中卸装该类，但是这样会使性能下降。如果关闭类垃圾回收，就可以消除由于多次装入和卸装同一个类而造成的开销。</p>
<p><strong>-XX:+UseParNewGC与-XX:+UseConcMarkSweepGC</strong></p>
<p>Eclipse算是与使用者交互非常频繁的应用程序，由于代码太多，在做全量编译或清理动作的时候，使用后台处理功能一边编译一边继续做其他的工作。适用于这种场景的当然非CMS垃圾收集器莫属了，所以采用了XX:+UseConcMarkSweepGC参数。至于XX:+UseParNewGC参数，其实ParNew收集器是使用CMS收集器后默认的新生代收集器，写上仅是为了看起来更清晰，CMS是用来收集年老代的。</p>
<p><strong>-XX:CMSInitiatingOccupancyFraction</strong></p>
<p>CMS默认年老代使用了68%就进行收集，所以Full GC次数还是会比较频繁，使用该参数将GC临界值提升到85%，这样收集器的效率就高许多了。</p>
<p><strong>-XX:ReservedCodeCacheSize</strong></p>
<p>设置代码缓存的最大值,这个是JIT即时编译器的配置选项，64m是MyEclipse的推荐值。</p>
<p><strong>-Duser.timezone</strong></p>
<p>这个配置是可选的，非性能选项，主要发现在我的xp系统下JVM里面的时区是+00，而不是+08，win7下正常，所以需要手工的指定下，如果没有这个情况出现的话可以忽略。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="Eclipse性能优化实践" href="http://terence2008.info/archives/eclipse-optimizing.html">《Eclipse性能优化实践》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/ajaxswing.html" title="AjaxSwing4.4.0授权码">AjaxSwing4.4.0授权码</a> (2)</li><li><a href="http://terence2008.info/archives/javamail_on_jdk8_ssl_problem.html" title="Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案">Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案</a> (0)</li><li><a href="http://terence2008.info/archives/myeclipse_dubug_maven_project.html" title="MyEclipse一站式调试Maven Web项目">MyEclipse一站式调试Maven Web项目</a> (0)</li><li><a href="http://terence2008.info/archives/wordpress_database_optimize.html" title="WordPress数据库的一处性能优化">WordPress数据库的一处性能优化</a> (1)</li><li><a href="http://terence2008.info/archives/spring_in_jdk_classes_loding_bug.html" title="Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题">Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题</a> (1)</li><li><a href="http://terence2008.info/archives/hibernate_criteria_order.html" title="Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作">Hibernate中变通使用Criteria API对自定义SQL表达式列进行排序操作</a> (2)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/eclipse-optimizing.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu的两种服务自启动模式</title>
		<link>http://terence2008.info/archives/ubuntu-service-autostart.html</link>
		<comments>http://terence2008.info/archives/ubuntu-service-autostart.html#comments</comments>
		<pubDate>Mon, 25 Nov 2013 03:56:08 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[服务器运维]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[运维]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=404</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 现行的Linux发行版主流的有两种init方式：一种是广为流传的System V initialization，它来源于Unix并且至今仍被各种Linux发行版所采用；另一种是近几年提出的Upstart方式，基于事件机制，系统所有服务的启动停止都是由事件驱动的。据我所知，采用后一种方式的目前有<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/ubuntu" title="查看 Ubuntu 的全部文章">Ubuntu</a></span>（6.10 and later），Fedora（9.10 and later），Debian（optional）。虽然采用Upstart的发行版并不多，但它旨在取代旧式的System V initialization。</p>
<p>&nbsp; &nbsp; &nbsp; 作为知识梳理，我总结一下这两种方式各自的初始化流程，这也是为了方便整理思路：</p>
<p>&nbsp; &nbsp; &nbsp; 之前在查找Linux系统init流程的相关资料时总是能够看到inittab的身影，但是在我的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/ubuntu" title="查看 Ubuntu 的全部文章">Ubuntu</a></span>上是没有这个文件的，到后来才知道采用Upstart方式的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/ubuntu" title="查看 Ubuntu 的全部文章">Ubuntu</a></span>上是没有inittab这个文件的。在旧式的System V initialization中，/etc/inittab可是个相当重要的文件。init进程启动后第一时间找的就是它。inittab负责初始化系统，设置系统runlevel及进入各runlevel对应要执行的命令。假设当前inittab中设置的默认runlevle是5，则init会运行/etc/init.d/rc 5命令，该命令会依据系统服务的依赖关系遍历执行/etc/rc5.d中的脚本。进入/etc/rc5.d目录可以发现里面的文件都是到/etc/init.d/下对应的脚本的软链接。以S开头的为启动的意思，以K开头的为停止。并且S/K后面的两位数数字代表了服务的启动顺序（由服务依赖关系决定）。</p>
<p>&nbsp; &nbsp; &nbsp; 那么Upstart job是怎么样的呢？我们知道，System V initializaiton是以runlevel为核心，依据服务间依赖关系的init方式，但在Upstart job，runlevel虽说对于服务的启动也有影响但已不是关键所在。Upstart job是事件驱动的，系统服务的启动停止等均是由事件决定的，反过来，系统服务的启动停止也可以作为事件源触发其他服务。并且事件并不一定得由系统内部产生，用户可以手工的键入start/stop [Service]产生事件来启动/终止服务。man upstart-evnets查看upstart job所定义的事件，可以发现，runlevel也被当作事件来对待（因runlevel的改变而产生的事件），诸如此类还有其他如 startup，started，filesystem等等。那么系统服务又是如何知道自己应该什么时候启动，什么时候终止的呢？答案就在于/etc/init中（有的发行版可能是在/etc/event.d中）。进入/etc/init目录下一看，均是系统服务的配置文件，或者说是job definition files（实际上Upstart init只需要/etc/init这么一个目录，不像System V init，“拐弯抹脚”转好多圈才到达目的地，在性能上不如前者）。随便打开一个文件，比如cron.conf：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cron - regular background program processing daemon</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># cron is a standard UNIX program that runs user-specified programs at</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># periodic scheduled times</span>
&nbsp;
description <span style="color: #ff0000;">&quot;regular background program processing daemon&quot;</span>
&nbsp;
start on runlevel <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">2345</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
stop on runlevel <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">!</span><span style="color: #000000;">2345</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
expect fork
&nbsp;
respawn
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exec</span> cron</pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 相信大家都发现了：start on runlevel [2345]；stop on runlevel [!2345]</p>
<p>&nbsp; &nbsp; &nbsp; 配置文件就是通过这个来设置服务何时启动，何时终止的。实际上并不仅仅在系统启动初期，在系统运转的任何时期都可以通过发送事件来启动或终止服务。这便是Upstart job的优点之一，除了用于系统初始化，还可以在系统运行阶段发挥作用。相比之下System V initialization方式下的配置文件一般只用于系统初始化阶段，当然系统运行阶段我们可以通过/etc/init.d/Service start/stop/otherCommand来操作服务，但很明显不如Upstart方式简洁明白。</p>
<p>&nbsp; &nbsp; &nbsp; 介绍完System V initialization和Upstart，那么现在就能介绍Ubuntu init系统初始化流程。前面提过Ubuntu使用的是Upstart方式的initialization，其实不全然，考虑到6.10之前的版本采用的System V init及某些服务的需要，Ubuntu采用的是兼容模式，即系统中既有System V-style启动的服务，也有Upstart启动的服务。如果你使用的是Ubuntu 12.04，那么可以看到系统中有这么几个目录：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d
<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>rc<span style="color: #800000;">${runlevel}</span>.d</pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 作为两种init方式各自特征的/etc/init.d，/etc/rc${runlevel}.d目录和/etc/init目录在Ubuntu中都有了，那么Ubuntu是如何实现兼容的？实际上，Ubuntu中并没有直接采用System V-style启动服务，要知道，Ubuntu中的init已被替换为Upstart init，而System V-style的服务是存放于/etc/rc${runlevel}.d目录中的，（而/etc/rc${runlevle}.d/下的文件是到/etc/init.d的软链接）可Upstart init并不会直接跑到这里面去启动服务。它是通过间接调用来启动这类服务的。换句话说，Ubuntu中的init并不会直接奔着/etc/init.d或者/etc/rc${runlevel}.d/而去，它采用了折衷的办法，通过/etc/init下的某些配置文件调用/etc/rc${runlevel}.d/中的脚本以启动采用旧式System V-style的服务。进入/etc/init目录（Upstart init会到该目录下读取配置文件），会发现几个跟rc有关的配置文件：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">rc.conf
rc-sysinit.conf
rcS.conf</pre></div></div>

<p>&nbsp; &nbsp; &nbsp; rc-sysinit在startup事件发生时被启动，rc在系统runlevel变化时被启动，rcS在系统runlevel为S时启动。在配置文件的注释中说明了，这几个文件，正是Upstart init处理System V-style服务的关键。rc-sysinit在startup事件发生时被启动，即Upstart init会首先读取rc-sysinit.conf并执行相关配置和脚本。rc-sysinit.conf的主要工作是设置系统默认runlevel，检测是否存在/etc/inittab或内核命令行，若存在，则按内核命令行 &gt; /etc/inittab &gt; 默认runlevel的顺序设置系统runlevel。最后调用telinit进入设置的runlevel。由于调用了telinit进入了设定的runlevel，runlevel改变的事件发生，此时rc服务启动（当然其他服务也会）。那么我们就有必要来看看rc.conf中到底有什么东西。打开rc.conf，注意到最后一行：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">exec</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>rc <span style="color: #007800;">$RUNLEVEL</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 是不是感觉/etc/init.d/rc很熟悉，没错，在System V initialization中，/etc/inittab中的各runlevel对应的命令行就是通过这种形式设置的。很明显，/etc/init.d/rc被调用了，并且传入了早前设置好的系统runlevel作为参数。而/etc/init.d/rc会根据传入的runlevel参数调用/etc/rc${runlevel}.d/下的脚本（以S开头）来启动服务，终止在前次runlevel启动而当前在 runlevel需要终止的服务。至此，Ubuntu处理System V-style服务的流程就比较明朗了。通过rc-sysinit和rc间接的调用/etc/init.d/rc从而启动System V-style服务，Ubuntu在采用新式Upstart init的同时照顾了旧式的System V init。</p>
<p>&nbsp; &nbsp; &nbsp; 另外补充一点，采用Upstart方式启动的服务在/etc/init/目录中一定有属于自己的一份配置文件，终端下键入：initctl list，可以发现列出的服务同/etc/init/下的服务完全一致。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="Ubuntu的两种服务自启动模式" href="http://terence2008.info/archives/ubuntu-service-autostart.html">《Ubuntu的两种服务自启动模式》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/ubuntu_old_sources.html" title="老版本Ubuntu 11.04等的源列表">老版本Ubuntu 11.04等的源列表</a> (1)</li><li><a href="http://terence2008.info/archives/backup-database-webroot.html" title="定时备份mysql和网站目录文件">定时备份mysql和网站目录文件</a> (0)</li><li><a href="http://terence2008.info/archives/blog_maintenance.html" title="博客维护日记">博客维护日记</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/ubuntu-service-autostart.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>招行网上银行专业版绿色安装脚本</title>
		<link>http://terence2008.info/archives/online_bank_green_installation.html</link>
		<comments>http://terence2008.info/archives/online_bank_green_installation.html#comments</comments>
		<pubDate>Tue, 19 Nov 2013 08:07:54 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[招行]]></category>
		<category><![CDATA[绿色安装]]></category>
		<category><![CDATA[网上银行]]></category>
		<category><![CDATA[脚本]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=400</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 貌似国内的各大<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%bd%91%e4%b8%8a%e9%93%b6%e8%a1%8c" title="查看 网上银行 的全部文章">网上银行</a></span>中只有<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%8b%9b%e8%a1%8c" title="查看 招行 的全部文章">招行</a></span>做成了软件客户端的形式，相比一般的普通网页版，它的安全性更高，windows平台间的兼容性更好，功能更强大，甚至可以做到USB KEY的免驱安装。虽然不适用于跨平台系统，但从日常便利性角度来说，毕竟大多数人会使用windows平台也就足够了。当然对于非windows系统用户，<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%8b%9b%e8%a1%8c" title="查看 招行 的全部文章">招行</a></span>还有专门的网页版，以及配套的插件。难怪说<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%8b%9b%e8%a1%8c" title="查看 招行 的全部文章">招行</a></span>的网银技术是国内所有银行里做得最好的，额，真有做广告的范啊 <img src='https://terence2008.info/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> &nbsp;</p>
<p>&nbsp; &nbsp; &nbsp; 说到这个客户端版本，招行称之为专业版，网页版的那个叫做大众版，其实基本上稍微有点存款的或者是公司发的工资卡都会为你免费办理专业版的网银的，这样就可以享受软件客户端带来的便利了。在这里，我们要讨论的是对于这个软件客户端的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%bb%bf%e8%89%b2%e5%ae%89%e8%a3%85" title="查看 绿色安装 的全部文章">绿色安装</a></span>方法，也没什么特别的意义，只是从软件和系统交互角度来分析它的运行机制和技术。</p>
<p>&nbsp; &nbsp; &nbsp; 通过软件逆向分析和整理，我制作出了软件绿化的安装和卸载<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%84%9a%e6%9c%ac" title="查看 脚本 的全部文章">脚本</a></span>，使用方法如下：</p>
<p>1.首先从招行官网下载安装程序<a href="http://www.cmbchina.com/cmbpb/v36/pb.htm" target="_blank">http://www.cmbchina.com/cmbpb/v36/pb.htm</a></p>
<p><a href="http://www.cmbchina.com/cmbpb/v36/pb.htm"></a>2.把下载到的PbSetup60.exe文件通过winrar或者7-zip进行解压</p>
<p>3.把@install.bat和@uninstall.bat拷贝到解压目录下，运行即可</p>
<p>@install.bat文件：</p>

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">cls
<span style="color: #33cc33;">@</span><span style="color: #b1b100; font-weight: bold;">echo</span> off
<span style="color: #b1b100; font-weight: bold;">cd</span> /d <span style="color: #33cc33;">%</span><span style="color: #448888;">~dp0</span>
regsvr32 /s PersonalBankMain.ocx
<span style="color: #00b100; font-weight: bold;">if</span> <span style="color: #33cc33;">%</span><span style="color: #448888;">errorlevel</span><span style="color: #33cc33;">%</span> <span style="color: #000000; font-weight: bold;">neq</span> <span style="color: #cc66cc;">0</span> <span style="color: #b1b100; font-weight: bold;">echo</span> 请使用右键--以管理员身份运行本脚本&amp;pause&gt;nul&amp;exit
regsvr32 /s CMBEdit.dll
<span style="color: #00b100; font-weight: bold;">if</span> &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">PROCESSOR_ARCHITECTURE</span><span style="color: #33cc33;">%</span>&quot; <span style="color: #000000; font-weight: bold;">neq</span> &quot;x86&quot; <span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">_64</span>
<span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">_86</span>
&nbsp;
:<span style="color: #b100b1; font-weight: bold;">_64</span>
<span style="color: #b1b100; font-weight: bold;">set</span> <span style="color: #448844;">vmbit</span>=<span style="color: #cc66cc;">64</span>
<span style="color: #b1b100; font-weight: bold;">copy</span> /y CertClient<span style="color: #33cc33;">%</span><span style="color: #448888;">vmbit</span><span style="color: #33cc33;">%</span>.dat &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\SysWOW64\drivers\CertClient.dat&quot;
<span style="color: #b1b100; font-weight: bold;">copy</span> /y CMBProtector<span style="color: #33cc33;">%</span><span style="color: #448888;">vmbit</span><span style="color: #33cc33;">%</span>.dat &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\SysWOW64\drivers\CMBProtector.dat&quot;
<span style="color: #b1b100; font-weight: bold;">copy</span> /y PBHttpComm.dll &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\SysWOW64\&quot;
<span style="color: #b1b100; font-weight: bold;">copy</span> /y PBFinanceMgr &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\SysWOW64\&quot;
sc create CMB8100 type= kernel start= auto binpath= &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\SysWOW64\drivers\CertClient.dat&quot; displayname= &quot;CMB8100&quot;
sc create CMBProtector type= kernel start= auto binpath= &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\SysWOW64\drivers\CMBProtector.dat&quot; displayname= &quot;CMBProtector&quot;
<span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">install</span>
&nbsp;
:<span style="color: #b100b1; font-weight: bold;">_86</span>
<span style="color: #b1b100; font-weight: bold;">copy</span> /y CertClient.dat &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\System32\drivers\CertClient.dat&quot;
<span style="color: #b1b100; font-weight: bold;">copy</span> /y CMBProtector.dat &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\System32\drivers\CMBProtector.dat&quot;
<span style="color: #b1b100; font-weight: bold;">copy</span> /y PBHttpComm.dll &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\System32\&quot;
<span style="color: #b1b100; font-weight: bold;">copy</span> /y PBFinanceMgr &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\System32\&quot;
sc create CMB8100 type= kernel start= auto binpath= &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\System32\drivers\CertClient.dat&quot; displayname= &quot;CMB8100&quot;
sc create CMBProtector type= kernel start= auto binpath= &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\System32\drivers\CMBProtector.dat&quot; displayname= &quot;CMBProtector&quot;
<span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">install</span>
&nbsp;
:<span style="color: #b100b1; font-weight: bold;">install</span>
net start CMB8100
net start CMBProtector
<span style="color: #b1b100; font-weight: bold;">echo</span> 安装完成！
<span style="color: #b1b100; font-weight: bold;">pause</span></pre></div></div>

<p>@uninstall.bat文件：</p>

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">cls
<span style="color: #33cc33;">@</span><span style="color: #b1b100; font-weight: bold;">echo</span> off
<span style="color: #b1b100; font-weight: bold;">cd</span> /d <span style="color: #33cc33;">%</span><span style="color: #448888;">~dp0</span>
CMBPBUninstall.exe
regsvr32 /u /s PersonalBankMain.ocx
regsvr32 /u /s CMBEdit.dll
net stop CMB8100
<span style="color: #00b100; font-weight: bold;">if</span> <span style="color: #33cc33;">%</span><span style="color: #448888;">errorlevel</span><span style="color: #33cc33;">%</span> <span style="color: #000000; font-weight: bold;">neq</span> <span style="color: #cc66cc;">0</span> <span style="color: #b1b100; font-weight: bold;">echo</span> 已经卸载过或者没有以管理员身份运行本脚本&amp;pause&gt;nul&amp;exit
sc delete CMB8100
net stop CMBProtector
sc delete CMBProtector
<span style="color: #00b100; font-weight: bold;">if</span> &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">PROCESSOR_ARCHITECTURE</span><span style="color: #33cc33;">%</span>&quot; <span style="color: #000000; font-weight: bold;">neq</span> &quot;x86&quot; <span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">_64</span>
<span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">_86</span>
&nbsp;
:<span style="color: #b100b1; font-weight: bold;">_64</span>
<span style="color: #b1b100; font-weight: bold;">del</span> /f /q &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\SysWOW64\drivers\CertClient.dat&quot;
<span style="color: #b1b100; font-weight: bold;">del</span> /f /q &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\SysWOW64\drivers\CMBProtector.dat&quot;
<span style="color: #b1b100; font-weight: bold;">del</span> /f /q &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\SysWOW64\PBHttpComm.dll&quot;
<span style="color: #b1b100; font-weight: bold;">del</span> /f /q &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\SysWOW64\PBFinanceMgr&quot;
reg delete &quot;HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\CMB&quot; /f
reg delete &quot;HKEY_CLASSES_ROOT\VirtualStore\MACHINE\SOFTWARE\Wow6432Node\CMB&quot; /f
reg delete &quot;HKEY_CURRENT_USER\Software\Classes\VirtualStore\MACHINE\SOFTWARE\Wow6432Node\CMB&quot; /f
<span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">uninstall</span>
&nbsp;
:<span style="color: #b100b1; font-weight: bold;">_86</span>
<span style="color: #b1b100; font-weight: bold;">del</span> /f /q &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\System32\drivers\CertClient.dat&quot;
<span style="color: #b1b100; font-weight: bold;">del</span> /f /q &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\System32\drivers\CMBProtector.dat&quot;
<span style="color: #b1b100; font-weight: bold;">del</span> /f /q &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\System32\PBHttpComm.dll&quot;
<span style="color: #b1b100; font-weight: bold;">del</span> /f /q &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">WinDir</span><span style="color: #33cc33;">%</span>\System32\PBFinanceMgr&quot;
reg delete &quot;HKEY_LOCAL_MACHINE\SOFTWARE\CMB&quot; /f
reg delete &quot;HKEY_CLASSES_ROOT\VirtualStore\MACHINE\SOFTWARE\CMB&quot; /f
reg delete &quot;HKEY_CURRENT_USER\Software\Classes\VirtualStore\MACHINE\SOFTWARE\CMB&quot; /f
<span style="color: #00b100; font-weight: bold;">goto</span> <span style="color: #b100b1; font-weight: bold;">uninstall</span>
&nbsp;
:<span style="color: #b100b1; font-weight: bold;">uninstall</span>
<span style="color: #b1b100; font-weight: bold;">rmdir</span> /s /q &quot;<span style="color: #33cc33;">%</span><span style="color: #448888;">USERPROFILE</span><span style="color: #33cc33;">%</span>\CMB&quot;
reg delete &quot;HKEY_CURRENT_USER\SOFTWARE\CMB&quot; /f
<span style="color: #b1b100; font-weight: bold;">echo</span> 卸载完成！
<span style="color: #b1b100; font-weight: bold;">pause</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 从中可以看到软件能运行的条件是启动2个系统内核级的服务以及注册相关ocx和dll文件，运行所产生的数据文件包括用户的数字证书都放在%USERPROFILE%\CMB文件夹中。另外在制作卸载<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%84%9a%e6%9c%ac" title="查看 脚本 的全部文章">脚本</a></span>的时候我注意到调用自带的CMBPBUninstall.exe后并不能完全清除残留在系统中的痕迹，所以后续的系统服务、文件以及注册表的删除操作是必不可少的，说明招行在一些细节方面做的还是不够好。ok，就先到这吧。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="招行网上银行专业版绿色安装脚本" href="http://terence2008.info/archives/online_bank_green_installation.html">《招行网上银行专业版绿色安装脚本》</a></div></blockquote><h3  class="related_post_title">随机日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/009.html" title="让flash植入代码符合xhtml标准">让flash植入代码符合xhtml标准</a> (1)</li><li><a href="http://terence2008.info/archives/chrome_firefox_earliest_release.html" title="Chrome和Firefox的最早Release版本">Chrome和Firefox的最早Release版本</a> (1)</li><li><a href="http://terence2008.info/archives/chrome_case_sensitive_search.html" title="Chrome进行大小写字符敏感的内容查找">Chrome进行大小写字符敏感的内容查找</a> (1)</li><li><a href="http://terence2008.info/archives/javamail_on_jdk8_ssl_problem.html" title="Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案">Javamail在JDK8上无法SSL连接QQ邮箱服务器的解决方案</a> (0)</li><li><a href="http://terence2008.info/archives/blog_maintenance.html" title="博客维护日记">博客维护日记</a> (0)</li><li><a href="http://terence2008.info/archives/unicode_encoding_conversion.html" title="Unicode编码在线转换工具">Unicode编码在线转换工具</a> (0)</li><li><a href="http://terence2008.info/archives/ubuntu_old_sources.html" title="老版本Ubuntu 11.04等的源列表">老版本Ubuntu 11.04等的源列表</a> (1)</li><li><a href="http://terence2008.info/archives/spring_in_jdk_classes_loding_bug.html" title="Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题">Spring容器在Oracle JDK和OpenJDK中的类装载差异导致的自动装箱bug问题</a> (1)</li><li><a href="http://terence2008.info/archives/change-space.html" title="换空间了">换空间了</a> (1)</li><li><a href="http://terence2008.info/archives/kindle3_cross_chaintool.html" title="分享自己做的Kindle3交叉编译工具链">分享自己做的Kindle3交叉编译工具链</a> (1)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/online_bank_green_installation.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>定时备份mysql和网站目录文件</title>
		<link>http://terence2008.info/archives/backup-database-webroot.html</link>
		<comments>http://terence2008.info/archives/backup-database-webroot.html#comments</comments>
		<pubDate>Wed, 06 Nov 2013 09:30:34 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[服务器运维]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[优化]]></category>
		<category><![CDATA[运维]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=388</guid>
		<description><![CDATA[<p>&nbsp; &nbsp; &nbsp; 今天继续维护网站，目的主要是为了能自动备份数据库和网站目录文件，然后使用crond服务设定计划任务成每天定时执行。写完shell脚本实验了一下感觉还不错，特把脚本文件共享出来以供参考。</p>
<p>&nbsp; &nbsp; &nbsp; 首先是自动备份数据库的脚本：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#This is a ShellScript For Auto DB Backup</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Setting</span>
<span style="color: #666666; font-style: italic;">#设置数据库名，数据库登录名，密码，备份路径，日志路径，数据文件位置，以及备份方式</span>
<span style="color: #666666; font-style: italic;">#默认情况下备份方式是tar，还可以是mysqldump</span>
<span style="color: #666666; font-style: italic;">#默认情况下，用root(空)登录mysql数据库，备份至/root/dbxxxxx.tar.gz</span>
<span style="color: #666666; font-style: italic;">#mysqldump情况下，会重启httpd服务</span>
<span style="color: #007800;">DBName</span>=db
<span style="color: #007800;">DBUser</span>=root
<span style="color: #007800;">DBPasswd</span>=
<span style="color: #007800;">BackupPath</span>=<span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #007800;">LogFile</span>=<span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>db.log
<span style="color: #007800;">DBPath</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #007800;">BackupMethod</span>=mysqldump
<span style="color: #666666; font-style: italic;">#BackupMethod=tar</span>
<span style="color: #666666; font-style: italic;">#Setting End</span>
&nbsp;
<span style="color: #007800;">NewFile</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$BackupPath</span>&quot;</span>db$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.tar.gz
<span style="color: #007800;">DumpFile</span>=db$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.sql
<span style="color: #007800;">OldFile</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$BackupPath</span>&quot;</span>db$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d <span style="color: #660033;">--date</span>=<span style="color: #ff0000;">'30 days ago'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>.tar.gz
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-------------------------------------------&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%y-%m-%d %H:%M:%S&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
<span style="color: #666666; font-style: italic;">#Delete Old File</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$OldFile</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
 <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$OldFile</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[<span style="color: #007800;">$OldFile</span>]Delete Old File Success!&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
<span style="color: #000000; font-weight: bold;">else</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[<span style="color: #007800;">$OldFile</span>]No Old Backup File!&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$NewFile</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[<span style="color: #007800;">$NewFile</span>]The Backup File is exists,Can't Backup!&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
<span style="color: #000000; font-weight: bold;">else</span>
 <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$BackupMethod</span> <span style="color: #000000; font-weight: bold;">in</span>
 mysqldump<span style="color: #7a0874; font-weight: bold;">&#41;</span>
     <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$BackupPath</span>
     service httpd stop <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
     <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$DBPasswd</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
     <span style="color: #000000; font-weight: bold;">then</span>
        mysqldump <span style="color: #660033;">-u</span> <span style="color: #007800;">$DBUser</span> <span style="color: #660033;">--opt</span> <span style="color: #007800;">$DBName</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$DumpFile</span>
     <span style="color: #000000; font-weight: bold;">else</span>
        mysqldump <span style="color: #660033;">-u</span> <span style="color: #007800;">$DBUser</span> -p<span style="color: #007800;">$DBPasswd</span> <span style="color: #660033;">--opt</span> <span style="color: #007800;">$DBName</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$DumpFile</span>
     <span style="color: #000000; font-weight: bold;">fi</span>
     <span style="color: #c20cb9; font-weight: bold;">tar</span> czvf <span style="color: #007800;">$NewFile</span> <span style="color: #007800;">$DumpFile</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
     <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[<span style="color: #007800;">$NewFile</span>]Backup Success!&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
     <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #007800;">$DumpFile</span>
     service httpd start <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
     <span style="color: #000000; font-weight: bold;">;;</span>
 <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
     <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>mysqld stop <span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
     <span style="color: #c20cb9; font-weight: bold;">tar</span> czvf <span style="color: #007800;">$NewFile</span> <span style="color: #007800;">$DBPath</span><span style="color: #007800;">$DBName</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
     <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>mysqld start <span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
     <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[<span style="color: #007800;">$NewFile</span>]Backup Success!&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
     <span style="color: #000000; font-weight: bold;">;;</span>
 <span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-------------------------------------------&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 随后是自动备份网站目录的脚本：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#This is a ShellScript For Web Files Backup</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Setting</span>
<span style="color: #666666; font-style: italic;">#设置备份路径，日志路径，web文件位置</span>
<span style="color: #666666; font-style: italic;">#默认情况下，备份至/root/webxxxxx.tar.gz</span>
<span style="color: #007800;">BackupPath</span>=<span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #007800;">LogFile</span>=<span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>web.log
<span style="color: #007800;">WebPath</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>html<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #666666; font-style: italic;">#Setting End</span>
&nbsp;
<span style="color: #007800;">NewFile</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$BackupPath</span>&quot;</span>web$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #7a0874; font-weight: bold;">&#41;</span>.tar.gz
<span style="color: #007800;">OldFile</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$BackupPath</span>&quot;</span>web$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d <span style="color: #660033;">--date</span>=<span style="color: #ff0000;">'30 days ago'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>.tar.gz
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-------------------------------------------&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%y-%m-%d %H:%M:%S&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--------------------------&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
<span style="color: #666666; font-style: italic;">#Delete Old File</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$OldFile</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
 <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$OldFile</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[<span style="color: #007800;">$OldFile</span>]Delete Old File Success!&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
<span style="color: #000000; font-weight: bold;">else</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[<span style="color: #007800;">$OldFile</span>]No Old Backup File!&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$NewFile</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[<span style="color: #007800;">$NewFile</span>]The Backup File is exists,Can't Backup!&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
<span style="color: #000000; font-weight: bold;">else</span>
 <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$WebPath</span>
 <span style="color: #c20cb9; font-weight: bold;">tar</span> czvf <span style="color: #007800;">$NewFile</span> . <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
 <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[<span style="color: #007800;">$NewFile</span>]Backup Success!&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;-------------------------------------------&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$LogFile</span></pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 最后就是cron脚本，这个比较简单，修改/etc/crontab文件就可以了：</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">SHELL</span>=<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span>
<span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin
<span style="color: #007800;">MAILTO</span>=root
<span style="color: #007800;">HOME</span>=<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># For details see man 4 crontabs</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Example of job definition:</span>
<span style="color: #666666; font-style: italic;"># .---------------- minute (0 - 59)</span>
<span style="color: #666666; font-style: italic;"># |  .------------- hour (0 - 23)</span>
<span style="color: #666666; font-style: italic;"># |  |  .---------- day of month (1 - 31)</span>
<span style="color: #666666; font-style: italic;"># |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...</span>
<span style="color: #666666; font-style: italic;"># |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat</span>
<span style="color: #666666; font-style: italic;"># |  |  |  |  |</span>
<span style="color: #666666; font-style: italic;"># *  *  *  *  * user-name command to be executed</span>
<span style="color: #000000;">0</span> <span style="color: #000000;">4</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> root <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>dbbackup.sh
<span style="color: #000000;">5</span> <span style="color: #000000;">4</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> root <span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>webbackup.sh</pre></div></div>

<p>&nbsp; &nbsp; &nbsp; 需要注意的是crontab修改完后需要重启crond服务，dbback.sh和webbackup.sh文件需要添加可执行权限。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="定时备份mysql和网站目录文件" href="http://terence2008.info/archives/backup-database-webroot.html">《定时备份mysql和网站目录文件》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/blog_maintenance.html" title="博客维护日记">博客维护日记</a> (0)</li><li><a href="http://terence2008.info/archives/ubuntu-service-autostart.html" title="Ubuntu的两种服务自启动模式">Ubuntu的两种服务自启动模式</a> (0)</li><li><a href="http://terence2008.info/archives/ubuntu_old_sources.html" title="老版本Ubuntu 11.04等的源列表">老版本Ubuntu 11.04等的源列表</a> (1)</li><li><a href="http://terence2008.info/archives/i-am-back.html" title="时隔三年我又回来啦">时隔三年我又回来啦</a> (2)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/backup-database-webroot.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>时隔三年我又回来啦</title>
		<link>http://terence2008.info/archives/i-am-back.html</link>
		<comments>http://terence2008.info/archives/i-am-back.html#comments</comments>
		<pubDate>Sun, 03 Nov 2013 13:42:34 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[优化]]></category>
		<category><![CDATA[域名]]></category>
		<category><![CDATA[阿里云]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=383</guid>
		<description><![CDATA[<p>　　终于把老博客网站给重新搭建起来了，算了下正好时隔三年。缘起今年9月的时候凑巧whois了下我的博客<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e5%9f%9f%e5%90%8d" title="查看 域名 的全部文章">域名</a></span>，发现已经是无主状态，赶紧上godaddy给抢注了回来，注册2年花了77软妹币。由于之前2010年<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e5%9f%9f%e5%90%8d" title="查看 域名 的全部文章">域名</a></span>到期后就没有再续费，等想起来的时候却发现早已被人家抢注，直到今年那人才把<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e5%9f%9f%e5%90%8d" title="查看 域名 的全部文章">域名</a></span>给放弃了，这才给了我续费的机会，虽然域名不值钱，但还是不喜欢再另注册一个了。</p>
<p>　　说到空间，当时用的虚拟主机是中国稳网，可把我坑的那个惨啊，经常挂掉，而且售后态度超差，总结出一个经验，服务器还是自己管理的好，性能该<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e4%bc%98%e5%8c%96" title="查看 优化 的全部文章">优化</a></span>的可以自己<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e4%bc%98%e5%8c%96" title="查看 优化 的全部文章">优化</a></span>。目前自己有个<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e9%98%bf%e9%87%8c%e4%ba%91" title="查看 阿里云 的全部文章">阿里云</a></span>的ecs，最低配置单核512内存，能免费用到明年下半年，等过期的时候坐等公司有优惠券发哈o(∩_∩)o 。其实等真正完全自己折腾网站的时候才发现，别看这小小的博客，还是挺耗主机资源的，最大的主就是内存。mysql倒还好说，可<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/apache" title="查看 apache 的全部文章">apache</a></span>+fastcgi无论怎么优化都会在分分钟内把内存给撑满了，没办法只好在prefork模式下降低并发支持。目前网站慢归慢，但好歹还算稳定，如果把内存加到1G的话估计就好好很多了，可惜ecs真心贵。。。</p>
<p>　　如何尽可能的降低网站对服务器资源的要求，这个问题我纠结了好久，首先是设置HTTP请求头中对部分资源的expire时间，做到浏览器不会每次刷新页面都会向服务器请求资源。然后就是页面的静态化，linux下博客页面静态化还是比较容易的，同时再启用gzip压缩，减少传输时间。这些都是服务器上能做的，接下来能优化的就是CDN了，<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e9%98%bf%e9%87%8c%e4%ba%91" title="查看 阿里云 的全部文章">阿里云</a></span>目前的CDN服务是免费试用的，也好，我就随便试下玩玩，不知道内陆地区目前访问本博客速度咋样。当然CDN加速和域名有着直接的关系，如果直接ip访问的话岂不是白弄了，所以得稍微改下<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/apache" title="查看 apache 的全部文章">apache</a></span>的配置，浏览器访问ip的时候直接返回403错误。可惜的是由于主机内存不给力，对并发做了限制后，访问网站经常会出现time out的问题，那就没法子了，但过一会儿一定能访问了╮(╯▽╰)╭</p>
<p>　　最后就是纯吐槽了，之所以到了11月才能上线不得不提备案的事，呃。。。之前的备案号不能用了，需要先注销再申请，前后整整拖了一个月，伤不起啊伤不起。还是奉劝一句能用国外的就尽量用国外的吧。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="时隔三年我又回来啦" href="http://terence2008.info/archives/i-am-back.html">《时隔三年我又回来啦》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/blog_maintenance.html" title="博客维护日记">博客维护日记</a> (0)</li><li><a href="http://terence2008.info/archives/ssl_cdn_choose.html" title="关于SSL证书与CDN加速的选择">关于SSL证书与CDN加速的选择</a> (0)</li><li><a href="http://terence2008.info/archives/backup-database-webroot.html" title="定时备份mysql和网站目录文件">定时备份mysql和网站目录文件</a> (0)</li><li><a href="http://terence2008.info/archives/001.html" title="写在最最开始">写在最最开始</a> (4)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/i-am-back.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>智能手机的另一大功能——造星</title>
		<link>http://terence2008.info/archives/android-iphone-girl.html</link>
		<comments>http://terence2008.info/archives/android-iphone-girl.html#comments</comments>
		<pubDate>Sun, 06 Jun 2010 07:04:14 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[视频]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=378</guid>
		<description><![CDATA[<p>　　自从iphone女在网上一举成名后，现今Android女又隆重登场，据说该<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%a7%86%e9%a2%91" title="查看 视频 的全部文章">视频</a></span>上传短短两天时间，点击率就已经超过了20万。iPhone女和Android女的人气暴涨说明了智能手机与Twitter、YouTube相结合正在成为一种造星的新途径。</p>
<p>　　其实也未必如此，当今这个充满着快餐文化的世界已无所谓途径了，各种各样的“XX门”就是很好的例子，暂且不谈那些<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%a7%86%e9%a2%91" title="查看 视频 的全部文章">视频</a></span>里的主角如何如何，作为广大的围观群众，只要人长的靓，或者够娱乐够刺激眼球就行，反正网络中的东西寿命一定不会太长，一阵风过去后一切都归于平静……</p>
<p>
<object type="application/x-shockwave-flash" width="480" height="400" data="http://player.youku.com/player.php/sid/XMTc2NjM1Nzcy/v.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://player.youku.com/player.php/sid/XMTc2NjM1Nzcy/v.swf" /></object>
</p>
<p>
<object type="application/x-shockwave-flash" width="480" height="400" data="http://player.youku.com/player.php/sid/XMTYwMTYwMDA0/v.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://player.youku.com/player.php/sid/XMTYwMTYwMDA0/v.swf" /></object></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="智能手机的另一大功能——造星" href="http://terence2008.info/archives/android-iphone-girl.html">《智能手机的另一大功能——造星》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/i-expect.html" title="我期待……">我期待……</a> (2)</li><li><a href="http://terence2008.info/archives/happy-mothers-day.html" title="母亲节——妈妈快乐！">母亲节——妈妈快乐！</a> (1)</li><li><a href="http://terence2008.info/archives/bird-dancing.html" title="鹦鹉版 杰克逊舞">鹦鹉版 杰克逊舞</a> (0)</li><li><a href="http://terence2008.info/archives/mario.html" title="没钱没车没房也想当英雄救公主？">没钱没车没房也想当英雄救公主？</a> (0)</li><li><a href="http://terence2008.info/archives/a-song.html" title="一首歌 两个人">一首歌 两个人</a> (0)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/014.html" title="天衣无缝的视频剪辑">天衣无缝的视频剪辑</a> (2)</li><li><a href="http://terence2008.info/archives/012.html" title="如果我是个男孩要带女朋友回家">如果我是个男孩要带女朋友回家</a> (0)</li><li><a href="http://terence2008.info/archives/011.html" title="朝鲜大妈，我被你吓到了= =！">朝鲜大妈，我被你吓到了= =！</a> (0)</li><li><a href="http://terence2008.info/archives/008.html" title="信春哥 死后四次原地满血复活">信春哥 死后四次原地满血复活</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/android-iphone-girl.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>浅谈不同浏览器地址栏中编码的差异</title>
		<link>http://terence2008.info/archives/thesis.html</link>
		<comments>http://terence2008.info/archives/thesis.html#comments</comments>
		<pubDate>Mon, 31 May 2010 09:51:59 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[网络技术]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[网络]]></category>
		<category><![CDATA[网页]]></category>
		<category><![CDATA[论文]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=374</guid>
		<description><![CDATA[<p>　　今天是上交学院专业<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%ae%ba%e6%96%87" title="查看 论文 的全部文章">论文</a></span>的最后一天，总算拼死拼活把它赶了出来……作为比赛<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%ae%ba%e6%96%87" title="查看 论文 的全部文章">论文</a></span>，档次当然没毕业论文那么高啦 <img src='https://terence2008.info/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  ，权当是娱乐而已，拿不拿奖就是另外一回事了。貌似这篇论文跟我的专业没什么必然的联系，倒是他们网工专业的刚好适合，但不知为什么写这类型的我就特别顺手。。。</p>
<h2>摘要：</h2>
<p>　　本文介绍了中文版本的IE、Firefox、Opera这三种主流的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%bd%91%e9%a1%b5" title="查看 网页 的全部文章">网页</a></span>浏览器在基于中文Windows操作系统下的地址栏中为了表示URL里的中文字符所采用的编码的差异，并且对各种可能情况进行适当地讨论，同时对所带来的各种实际问题做出解决方案。</p>
<h2>关键词：</h2>
<p>　　浏览器，汉字编码，URL，网站开发，搜索引擎</p>
<h2>Abstract:</h2>
<p>　　In this article, introduces the Chinese version of the Opera, IE, Firefox 3 kinds of mainstream web browser Windows operating system based on Chinese in the address bar to the URL in using Chinese characters, and the difference of coding possible situation, appropriately discussed the problems caused by making solutions.</p>
<h2>Key words:</h2>
<p>　　Internet browser, Chinese character encoding, URL, Web development, Search engines</p>
<p><br class="spacer_" /></p>
<p><strong>1.</strong><strong>引言</strong></p>
<p>　　我们使用<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%bd%91%e9%a1%b5" title="查看 网页 的全部文章">网页</a></span>浏览器打开搜索引擎，搜索中文关键字的时候有否注意过在地址栏中有类似于“%E4%B8%AD%E5%9B%BD”这样的奇怪的字符串呢？而在搜索英文关键字时，地址栏中却就可以正常显示出真正要在查找的关键词？我们所要探讨的问题就是为什么地址栏中不直接显示中文而是一堆看似杂乱无章的“乱码”。</p>
<p><strong>2.</strong><strong>地址传输原理</strong></p>
<p>　　关于URL地址的传输，我们还得先从HTTP协议入手。首先，浏览器与<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%bd%91%e7%bb%9c" title="查看 网络 的全部文章">网络</a></span>服务器建立TCP连接，连接建立后，向<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%bd%91%e7%bb%9c" title="查看 网络 的全部文章">网络</a></span>服务器发出访问请求。HTTP 定义了浏览器与网络服务器交互的不同方法，最基本的方法是 GET 和 POST，根据协议，这两种方式中都包含了客户端的IP地址、浏览器类型和请求的URL。当然，两者之间还是有比较明显的区别：</p>
<p>　　（1）在浏览器，GET方式是通过URL提交数据，数据在URL中是可见的；而POST方式，数据是放置在HTML的Header内提交的。</p>
<p>　　（2）GET方式提交的数据最多只能有4096字节（以IE6为例），而POST就没有此限制。</p>
<p>　　（3）安全性问题。正如在（1）中提到的，使用GET的时候，参数会显示在地址栏中，而POST不会。所以如果传输的数据是非敏感数据，那么可以使用GET；如果请求的数据包含敏感内容，那么还是使用POST为好。</p>
<p><strong>3.</strong><strong>搜索引擎的请求响应</strong></p>
<p>　　对于一般普遍的搜索引擎，其发送的请求是用的是GET方式。在中文IE浏览器中打开<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/google" title="查看 Google 的全部文章">Google</a></span>，搜索关键词“我”，结果页面打开后，地址栏中显示的是“http://www.google.com.hk/search?hl=zh-CN&amp;source=hp&amp;q=%E6%88%91”，我们再来看下在Firefox浏览器中的表现，输入同样的关键字，地址栏中显示的是“http://www.google.com.hk/search?hl=zh-CN&amp;source=hp&amp;q=我”，个别情况下显示的是“http://www.google.com.hk/search?hl=zh-CN&amp;source=hp&amp;q=%CE%D2”，而在Opera中，其表现得与IE类似。当然，那些百分号加数字很明显代表的就是汉字的编码，目前我们比较常用的是GBK和UTF-8编码字符集。以上都是通过GET请求，参数用中文字符串的例子。</p>
<p>　　问题由此引出，为什么不同的浏览器会有不同的中文表示方法？</p>
<p><strong>4.</strong><strong>汉字在电脑上的编码</strong></p>
<p>　　首先我们要了解下汉字的编码。众所周知，电脑中的每个字符归根结底都是由1和0组成，而电脑是由美国最先研制出来的，所以字符只局限于26个英文字母和若干种符号，每个字符都有对应的ASCII码，如果想要在电脑上表示一个中文字符，就必须先经过编码。任何编码都需要一个共同约定的规范，我们的前辈在汉字编码上所做出的成就是伟大的。以下是现今较为流行的汉字编码方式：</p>
<p>　　GBK：GBK编码是GB2312的升级版，GB2312是“中华人民共和国国家汉字信息交换用编码”，由国家标准总局发布，1981年5月1日起实施，通行于大陆，新加坡等地也使用此编码。GB2312收录简化汉字及符号、字母、日文假名等共7445个图形字符，其中汉字占6763个。GB2312规定“对任意一个图形字符都采用两个字节表示，每个字节均采用七位编码表示”，习惯上称第一个字节为“高字节”，第二个字节为“低字节”。GB2312将代码表分为94个区，对应第一字节；每个区94个位，对应第二字节，两个字节的值分别为区号值和位号值加32（2OH）,因此也称为区位码。01-09区为符号、数字区，16-87区为汉字区，10-15区、88-94区是有待进一步标准化的空白区。GB2312最多能表示6763个汉字。但随着时间推移及汉字文化的不断延伸推广，有些原来很少用的字，现在变成了常用字，只能编码6763个汉字就显得捉襟见肘了。所以了为了解决这些问题，以及配合UNICODE的实施，全国信息技术化技术委员会于1995年12 月1日发布GBK。GBK向下与GB2312 完全兼容，向上支持ISO 10646国际标准，起到了承上启下的作用。GBK 亦采用双字节表示，总体编码范围为8140-FEFE之间，共收录21886个汉字和图形符号，简繁体字融于同一库。</p>
<p>　　UTF-8：UTF-8编码是用以解决国际上字符的一种多字节编码，它对英文使用一个字节，中文使用三个字节来编码。UTF-8包含全世界所有国家需要用到的字符，是国际编码，通用性强。UTF-8编码的文字可以在各国支持UTF8字符集的浏览器上显示。如果是UTF8编码，则在外国人的英文浏览器上也能显示中文，而无需下载相应的中文语言支持包。</p>
<p>　　下表以汉字“中国”为例，用不同的编码在实际计算机中存储的差异：</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="54">
<p><strong>汉字</strong><strong> </strong></p>
</td>
<td width="52">
<p><strong>编码</strong><strong> </strong></p>
</td>
<td width="170">
<p><strong>二进制表示</strong><strong> </strong></p>
</td>
</tr>
<tr>
<td width="54">
<p>中国</p>
</td>
<td width="52">
<p>UTF-8</p>
</td>
<td width="170">
<p>0xe4 0xb8 0xad 0xe5 0x9b 0xbd</p>
</td>
</tr>
<tr>
<td width="54">
<p>中国</p>
</td>
<td width="52">
<p>GBK</p>
</td>
<td width="170">
<p>0xd6 0xd0 0xb9 0xfa</p>
</td>
</tr>
</tbody>
</table>
<p><br class="spacer_" /></p>
<p><strong>5.</strong><strong>浏览器与服务器间的编码通讯</strong></p>
<p>　　不管对于任何一款浏览器来说，一个HTTP请求都得经过的以下三个环节：</p>
<p>　　　　浏览器（GET/POST） → 网络服务器 → 浏览器显示</p>
<p>　　（1）浏览器把URL经过编码后发送给WEB服务器。</p>
<p>　　（2）WEB服务器把这些内容解码转换为UNICODE，处理完毕后，再把结果(即<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%bd%91%e9%a1%b5" title="查看 网页 的全部文章">网页</a></span>)编码返回给浏览器。</p>
<p>　　（3）浏览器按照指定的编码显示该网页。</p>
<p>　　鉴于中文编码的非唯一性，对于第（1）环节，我们可以用一个实验来证明之：在IE浏览器中打开<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/google" title="查看 Google 的全部文章">Google</a></span>，可以发现<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/google" title="查看 Google 的全部文章">Google</a></span>的编码是UTF-8，将网页编码强制修改为GB2312，此时，页面上的中文会变成乱码，不理它，在文本框中输入“我”然后提交，地址栏中会将其编码为“%CE%D2”而不是在上面提到的正常情况下所表示的“%E6%88%91”。由此可见，浏览器在发往服务器前，对参数内容进行URL编码使用的就是浏览器编码 。</p>
<p>　　同时，以上的实验说明了不同的浏览器在各种情况下对汉字的编码有着不同的处理方法。</p>
<p>　　URL地址中有PathInfo和QueryString两种变量，其中QueryString又叫参数。比如“http://localhost/example/中国?name=中国”，其中第一个“中国”是PathInfo，第二个就是QueryString。地址通过GET方式提交，浏览器会对URL进行URL Encode，不同的浏览器对于PathInfo和QueryString的支持各不一样。通过实验和查找了相关资料，现将结果整理如下：</p>
<p>　　（1）对于IE，如果在“选项——高级”选项中选中“总以UTF-8发送(默认方式)”，则PathInfo的是按照UTF-8编码，QueryString是按照GBK编码的，其中QueryString不进行URL encode。</p>
<p>　　在浏览器中输入：</p>
<p>　　http://localhost/example/中国?name=中国</p>
<p>　　实际的提交是：</p>
<p>　　GET /example/%E4%B8%AD%E5%9B%BD?name=%D6%D0%B9%FA</p>
<p>　　（2）对于IE，如果取消“总以UTF-8发送”，则PathInfo和QueryString都按照GBK编码，同时两者都不进行URL encode。</p>
<p>　　实际的提交是：</p>
<p>　　GET /example/%D6%D0%B9%FA?name=%D6%D0%B9%FA</p>
<p>　　（3）对于Firefox，默认方式下PathInfo和QueryString都按照UTF-8编码。</p>
<p>　　实际的提交是：</p>
<p>　　GET /example/%E4%B8%AD%E5%9B%BD?name=%E4%B8%AD%E5%9B%BD</p>
<p>　　（4）对于Firefox，在其地址栏中输入“about:config”，找到选项“network.standard-url.encode-utf8”，设置为“False”，即可改变发送PathInfo和QueryString的编码方式为GBK。</p>
<p>　　实际的提交是：</p>
<p>　　GET /example/%D6%D0%B9%FA?name=%D6%D0%B9%FA</p>
<p>　　需要说明的是在这两种情况下，Firefox有时会“自作聪明”一点，如果参数里有它认识的URL encode后的字符串时，它就会自动恢复成原始中文显示，以增加URL友好显示程度。</p>
<p>　　（5）对于Opera，则PathInfo和QueryString都按照UTF-8编码。</p>
<p>　　实际的提交是：</p>
<p>　　GET /example/%E4%B8%AD%E5%9B%BD?name=%E4%B8%AD%E5%9B%BD</p>
<p><strong>6.</strong><strong>结论</strong></p>
<p>　　需要说明的是，以上实验都是在中文Windows系统、中文版的浏览器下测试通过的。很显然，不同的浏览器甚至同一浏览器的不同设置，都会影响最终发送的URL编码。所以为了不必要的麻烦，开发网站过程中，URL尽量不要使用中文，如果写入网页中的链接包括中文字符，最好使用URL encode处理，才能和当前网页编码无关，否则可能会造成不能正确访问。</p>
<p><strong>7.</strong><strong>解决方案</strong></p>
<p>　　但事情不是那么绝对的，测试过百度搜索引擎，不管在IE中开不开启“总以UTF-8发送”，URL中的中文编码总是保持GB2312编码不变，这就不得不说到“动态识别字符编码”技术，它通过网页中添加“&lt;meta http-equiv=content-type content="text/html; charset=gb2312"&gt;”这样的约定标记或者进行编码规律识别来使中文总以指定的编码来打开页面。</p>
<p>　　鉴于不同浏览器之间编码时采用的字符集不同，在开发网站时，本文给出如下建议：</p>
<p>　　（1）不同的WEB服务器端对各种编码的URL处理也不相同，所以尽量不要使用中文字符作文件名。</p>
<p>　　（2）很多情况下浏览器的地址栏看到URL并不等同于发送到WEB服务器的URL，要正确查看浏览器发送的到服务器URL，最好借助一些工具分析HTTP的请求头。</p>
<p>　　（3）一定要考虑到不同环境下URL编码的不同，才能实现系统更好的兼容性，兼容性好的系统必须要能够识别来自客户端URL的编码，才能正确地处理地址。</p>
<p>　　（4）建议URL中的URL encode编码的字符集和网页的Content Type的字符集采用相同的字符集，这样程序的实现就变得很简单，不需要做复杂的编码转换了。</p>
<h2>参考文献：</h2>
<p>　　[1] (日)小泉. WEB技术——HTTP到服务器端. 科学出版社</p>
<p>　　[2] 宫垂刚,韦一,张华丰等. PHP完全自学手册. 机械工业出版社</p>
<p>　　[3] wangjun_1218. 浏览器URL编码.  http://blog.csdn.net/wangjun_1218/archive/2009/07/08/4330244.aspx</p>
<p>　　[4] guobin. 不可能的任务：地址栏用中文参数. http://blog.sina.com.cn/s/blog_3f63cc9d0100a92y.html</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="浅谈不同浏览器地址栏中编码的差异" href="http://terence2008.info/archives/thesis.html">《浅谈不同浏览器地址栏中编码的差异》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/google-adsense.html" title="巧用Google AdSense赚美元">巧用Google AdSense赚美元</a> (1)</li><li><a href="http://terence2008.info/archives/013.html" title="Google阅读器里RSS的显示问题">Google阅读器里RSS的显示问题</a> (0)</li><li><a href="http://terence2008.info/archives/ajaxswing.html" title="AjaxSwing4.4.0授权码">AjaxSwing4.4.0授权码</a> (2)</li><li><a href="http://terence2008.info/archives/tinymce-firefox.html" title="TinyMCE编辑器对FireFox的兼容不太好">TinyMCE编辑器对FireFox的兼容不太好</a> (1)</li><li><a href="http://terence2008.info/archives/010.html" title="网页中连续字符手动换行的方法">网页中连续字符手动换行的方法</a> (0)</li><li><a href="http://terence2008.info/archives/006.html" title="电子杂志《物华特刊》发布！">电子杂志《物华特刊》发布！</a> (2)</li><li><a href="http://terence2008.info/archives/005.html" title="猜想2010年后的中国网络">猜想2010年后的中国网络</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/thesis.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>我期待……</title>
		<link>http://terence2008.info/archives/i-expect.html</link>
		<comments>http://terence2008.info/archives/i-expect.html#comments</comments>
		<pubDate>Wed, 26 May 2010 04:19:50 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[校园]]></category>
		<category><![CDATA[视频]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=372</guid>
		<description><![CDATA[<p>我期待，我能穿过光阴的空隙</p>
<p>一览无余天际的表情</p>
<p>此刻的良辰美景</p>
<p>平淡中藏匿着诗意</p>
<p>世界比想象中更不可理喻</p>
<p>希望可以人淡如菊</p>
<p>黑暗和光明</p>
<p>听从内心的倾诉</p>
<p>喧嚣中，日子慢慢地被耗尽</p>
<p>我期待，有一天我会明白</p>
<p>反复前后迂回地试探</p>
<p>都是生活中不可缺少的体验</p>
<p>我期待，</p>
<p>未来</p>
<p>回头发现自己是对的</p>
<p>然后转过头去</p>
<p>昂首阔步不留下一丝遗憾</p>
<p>我期待……</p>
<p>
<object type="application/x-shockwave-flash" width="480" height="400" data="http://player.youku.com/player.php/sid/XMTYwNjUxMDY4/v.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://player.youku.com/player.php/sid/XMTYwNjUxMDY4/v.swf" /></object></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="我期待……" href="http://terence2008.info/archives/i-expect.html">《我期待……》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/android-iphone-girl.html" title="智能手机的另一大功能——造星">智能手机的另一大功能——造星</a> (2)</li><li><a href="http://terence2008.info/archives/happy-mothers-day.html" title="母亲节——妈妈快乐！">母亲节——妈妈快乐！</a> (1)</li><li><a href="http://terence2008.info/archives/bird-dancing.html" title="鹦鹉版 杰克逊舞">鹦鹉版 杰克逊舞</a> (0)</li><li><a href="http://terence2008.info/archives/mario.html" title="没钱没车没房也想当英雄救公主？">没钱没车没房也想当英雄救公主？</a> (0)</li><li><a href="http://terence2008.info/archives/a-song.html" title="一首歌 两个人">一首歌 两个人</a> (0)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/014.html" title="天衣无缝的视频剪辑">天衣无缝的视频剪辑</a> (2)</li><li><a href="http://terence2008.info/archives/012.html" title="如果我是个男孩要带女朋友回家">如果我是个男孩要带女朋友回家</a> (0)</li><li><a href="http://terence2008.info/archives/011.html" title="朝鲜大妈，我被你吓到了= =！">朝鲜大妈，我被你吓到了= =！</a> (0)</li><li><a href="http://terence2008.info/archives/008.html" title="信春哥 死后四次原地满血复活">信春哥 死后四次原地满血复活</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/i-expect.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>母亲节——妈妈快乐！</title>
		<link>http://terence2008.info/archives/happy-mothers-day.html</link>
		<comments>http://terence2008.info/archives/happy-mothers-day.html#comments</comments>
		<pubDate>Sun, 09 May 2010 10:52:21 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[节日]]></category>
		<category><![CDATA[视频]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=370</guid>
		<description><![CDATA[<p>　　以前往往都会忽略有这样一个<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%8a%82%e6%97%a5" title="查看 节日 的全部文章">节日</a></span>，直到看到身边的朋友纷纷打电话到家里问候自己的妈妈时，才忽然发现自己总是感觉的理所当然的想法有多么得无知。总以为妈妈会明白我会想什么，当发现事实并非如此的时候去责怪去生气，当妈妈生日的时候也从没想过去买些小东西表达一下……我知道我错了，从今天起我一定要变得懂事，妈妈，<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%8a%82%e6%97%a5" title="查看 节日 的全部文章">节日</a></span>快乐！</p>
<p>
<object type="application/x-shockwave-flash" width="480" height="400" data="http://player.youku.com/player.php/sid/XMTcxMDE3NjQ4/v.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://player.youku.com/player.php/sid/XMTcxMDE3NjQ4/v.swf" /></object></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="母亲节——妈妈快乐！" href="http://terence2008.info/archives/happy-mothers-day.html">《母亲节——妈妈快乐！》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/android-iphone-girl.html" title="智能手机的另一大功能——造星">智能手机的另一大功能——造星</a> (2)</li><li><a href="http://terence2008.info/archives/i-expect.html" title="我期待……">我期待……</a> (2)</li><li><a href="http://terence2008.info/archives/bird-dancing.html" title="鹦鹉版 杰克逊舞">鹦鹉版 杰克逊舞</a> (0)</li><li><a href="http://terence2008.info/archives/mario.html" title="没钱没车没房也想当英雄救公主？">没钱没车没房也想当英雄救公主？</a> (0)</li><li><a href="http://terence2008.info/archives/a-song.html" title="一首歌 两个人">一首歌 两个人</a> (0)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/014.html" title="天衣无缝的视频剪辑">天衣无缝的视频剪辑</a> (2)</li><li><a href="http://terence2008.info/archives/012.html" title="如果我是个男孩要带女朋友回家">如果我是个男孩要带女朋友回家</a> (0)</li><li><a href="http://terence2008.info/archives/011.html" title="朝鲜大妈，我被你吓到了= =！">朝鲜大妈，我被你吓到了= =！</a> (0)</li><li><a href="http://terence2008.info/archives/008.html" title="信春哥 死后四次原地满血复活">信春哥 死后四次原地满血复活</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/happy-mothers-day.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>六种查找算法效率比较</title>
		<link>http://terence2008.info/archives/finding_compare.html</link>
		<comments>http://terence2008.info/archives/finding_compare.html#comments</comments>
		<pubDate>Tue, 04 May 2010 10:49:26 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[算法]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=367</guid>
		<description><![CDATA[<p>　　接着上次的<a href="/archives/sorting_compare.html">排序算法讨论</a>，这次谈的是六种查找<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%ae%97%e6%b3%95" title="查看 算法 的全部文章">算法</a></span>，分别是：顺序查找、折半查找、二叉树查找、索引查找、开地址哈希查找方法、拉链法哈希查找方法。</p>
<p>　　由于查找一个数的过程，无论运用哪种<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%ae%97%e6%b3%95" title="查看 算法 的全部文章">算法</a></span>对于电脑来说速度都是非常快的，都在1ms之内，无法用计时函数测试出来。所以为了能够直观准确地表示出各个算法间的差异，此程序用了循环查找的方法，具体的思想是：先随机生成3000个数作为查找的数据源，再随机生成3000（也可以少一点）个数作为被查找的数，让当前的查找算法运行一趟，这样就相当于运行了3000次。</p>
<p>　　这样还不具有一定的客观性，用flag标记出刚刚运行完查找后的结果，从数据源中找到目标的数标记为1，没找到的标记为0，并以此存为两个数组，最后我们就可以使用这两个数组再次分别进行循环查找，同时开始计时。如此一来就可以计算出各个算法在查找成功的情况下需要多少时间，反之在没查找到的情况下需多长时间了。代码如下：</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
<span style="color: #339933;">#include &lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include &lt;time.h&gt;</span>
<span style="color: #339933;">#include &lt;windows.h&gt;</span>
&nbsp;
<span style="color: #339933;">#define ListSize 3000</span>
<span style="color: #339933;">#define TableSize ListSize*5/4</span>
<span style="color: #339933;">#define  NULLKEY  0</span>
&nbsp;
<span style="color: #993333;">typedef</span> <span style="color: #993333;">int</span> KeyType<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span>
<span style="color: #009900;">&#123;</span>
	KeyType key<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>RecordType<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> node
<span style="color: #009900;">&#123;</span>
	KeyType key<span style="color: #339933;">;</span>
	<span style="color: #993333;">struct</span> node <span style="color: #339933;">*</span>lchild<span style="color: #339933;">,*</span>rchild<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>BSTNode<span style="color: #339933;">,*</span>BSTree<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span>
<span style="color: #009900;">&#123;</span>
    KeyType r<span style="color: #009900;">&#91;</span>ListSize<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> Length<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>RecordList<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span>  <span style="color: #666666; font-style: italic;">//索引表结点</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> key<span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">//最大关键字域</span>
	<span style="color: #993333;">int</span> link<span style="color: #339933;">;</span>    <span style="color: #666666; font-style: italic;">//指向本块第一个结点的位置</span>
<span style="color: #009900;">&#125;</span>Index<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span>   <span style="color: #666666; font-style: italic;">//顺序表结点</span>
<span style="color: #009900;">&#123;</span>  
	<span style="color: #993333;">int</span> key<span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">//关键字域</span>
<span style="color: #009900;">&#125;</span>Dexlist<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">typedef</span> <span style="color: #993333;">struct</span> Node<span style="color: #009900;">&#123;</span>	
	<span style="color: #993333;">int</span> data<span style="color: #339933;">;</span>
	<span style="color: #993333;">struct</span> Node <span style="color: #339933;">*</span>next<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>Node<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">typedef</span> RecordType HashTable<span style="color: #009900;">&#91;</span>TableSize<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
Dexlist dexlist<span style="color: #009900;">&#91;</span>ListSize<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
Index index<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
RecordList list<span style="color: #339933;">;</span>
HashTable hashtable<span style="color: #339933;">;</span>
BSTree <span style="color: #339933;">*</span>bst<span style="color: #339933;">;</span>
Node <span style="color: #339933;">**</span>A<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> SeqSearch<span style="color: #009900;">&#40;</span>RecordList l<span style="color: #339933;">,</span>KeyType k<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> InSort<span style="color: #009900;">&#40;</span>RecordList <span style="color: #339933;">*</span>l<span style="color: #339933;">,</span><span style="color: #993333;">int</span> length<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> BinSrch<span style="color: #009900;">&#40;</span>RecordList l<span style="color: #339933;">,</span>KeyType k<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> InsertBST<span style="color: #009900;">&#40;</span>BSTree <span style="color: #339933;">*</span>bst<span style="color: #339933;">,</span> KeyType x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> CreateBST<span style="color: #009900;">&#40;</span>BSTree <span style="color: #339933;">*</span>bst<span style="color: #339933;">,</span>RecordList list<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> SearchBST<span style="color: #009900;">&#40;</span>BSTree bst<span style="color: #339933;">,</span>KeyType key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> CreatIndex<span style="color: #009900;">&#40;</span>Dexlist dl<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>Index index<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>RecordList list<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> IndexSearch<span style="color: #009900;">&#40;</span>Dexlist r<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>Index index<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> Hash<span style="color: #009900;">&#40;</span>KeyType k<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> CreatHashTable<span style="color: #009900;">&#40;</span>RecordList l<span style="color: #339933;">,</span><span style="color: #993333;">int</span> SIZE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span>  HashSearch<span style="color: #009900;">&#40;</span>HashTable ht<span style="color: #339933;">,</span> KeyType K<span style="color: #339933;">,</span><span style="color: #993333;">int</span> SIZE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> InitHash<span style="color: #009900;">&#40;</span>Node <span style="color: #339933;">**</span>Q<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> InsertHash<span style="color: #009900;">&#40;</span>Node <span style="color: #339933;">**</span>Q<span style="color: #339933;">,</span><span style="color: #993333;">int</span> value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">int</span> SearchHash<span style="color: #009900;">&#40;</span>Node <span style="color: #339933;">**</span>Q<span style="color: #339933;">,</span><span style="color: #993333;">int</span> value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">int</span> CaseChoice<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> choice<span style="color: #339933;">,</span><span style="color: #993333;">int</span> x<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span>k<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>flag<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
		bst<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>BSTree <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>BSTree<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>choice<span style="color: #339933;">==</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		k<span style="color: #339933;">=</span>SeqSearch<span style="color: #009900;">&#40;</span>list<span style="color: #339933;">,</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> k<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>choice<span style="color: #339933;">==</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		InSort<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>list<span style="color: #339933;">,</span>ListSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		k<span style="color: #339933;">=</span>BinSrch<span style="color: #009900;">&#40;</span>list<span style="color: #339933;">,</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> k<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>choice<span style="color: #339933;">==</span><span style="color: #0000dd;">3</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		CreateBST<span style="color: #009900;">&#40;</span>bst<span style="color: #339933;">,</span>list<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		k<span style="color: #339933;">=</span>SearchBST<span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>bst<span style="color: #339933;">,</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> k<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>choice<span style="color: #339933;">==</span><span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		flag<span style="color: #339933;">=</span>CreatIndex<span style="color: #009900;">&#40;</span>dexlist<span style="color: #339933;">,</span>index<span style="color: #339933;">,</span>list<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>flag<span style="color: #009900;">&#41;</span> 
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>对不起！索引表创建失败<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		k<span style="color: #339933;">=</span>IndexSearch<span style="color: #009900;">&#40;</span>dexlist<span style="color: #339933;">,</span>index<span style="color: #339933;">,</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> k<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>choice<span style="color: #339933;">==</span><span style="color: #0000dd;">5</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		CreatHashTable<span style="color: #009900;">&#40;</span>list<span style="color: #339933;">,</span>TableSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		k<span style="color: #339933;">=</span>HashSearch<span style="color: #009900;">&#40;</span>hashtable<span style="color: #339933;">,</span>x<span style="color: #339933;">,</span>TableSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> k<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>choice<span style="color: #339933;">==</span><span style="color: #0000dd;">6</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		A<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>Node <span style="color: #339933;">**</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>Node<span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//申请一个指针型数组A[n]</span>
		InitHash<span style="color: #009900;">&#40;</span>A<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//初始化数组A</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span>ListSize<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
			InsertHash<span style="color: #009900;">&#40;</span>A<span style="color: #339933;">,</span>list.<span style="color: #202020;">r</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//print_hash(A,n);</span>
		k<span style="color: #339933;">=</span>SearchHash<span style="color: #009900;">&#40;</span>A<span style="color: #339933;">,</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> k<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>choice<span style="color: #339933;">==</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#41;</span>
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>    输入错误！<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		exit<span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span>j<span style="color: #339933;">,</span>x<span style="color: #339933;">,</span>choice<span style="color: #339933;">,</span>k<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	list.<span style="color: #202020;">Length</span><span style="color: #339933;">=</span>ListSize<span style="color: #339933;">;</span>
	srand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span><span style="color: #009900;">&#41;</span>time<span style="color: #009900;">&#40;</span>NULL<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">double</span> runtime<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> T<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>F<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> success<span style="color: #009900;">&#91;</span>ListSize<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>fail<span style="color: #009900;">&#91;</span>ListSize<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #993333;">long</span> dwStart<span style="color: #339933;">,</span>dwEnd<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">do</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>=========六种查找算法效率比较=========&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>	1. 顺序查找&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>        2. 折半查找&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>        3. 二叉树查找&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>        4. 索引查找&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>        5. 开地址法哈希查找(α=0.8)&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>        6. 拉链法哈希查找&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>        7. 退出<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>======================================&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>    请输入您的选择 (1,2,3,4,5,6,7)：&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		scanf<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%d&quot;</span><span style="color: #339933;">,&amp;</span>choice<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>ListSize<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			j<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">10000.0</span><span style="color: #339933;">*</span>rand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>RAND_MAX<span style="color: #339933;">+</span><span style="color:#800080;">1.0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			list.<span style="color: #202020;">r</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>j<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		bst<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>BSTree <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>BSTree<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		srand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span><span style="color: #009900;">&#41;</span>time<span style="color: #009900;">&#40;</span>NULL<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>ListSize<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			j<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color:#800080;">10000.0</span><span style="color: #339933;">*</span>rand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>RAND_MAX<span style="color: #339933;">+</span><span style="color:#800080;">1.0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			x<span style="color: #339933;">=</span>j<span style="color: #339933;">;</span>
			k<span style="color: #339933;">=</span>CaseChoice<span style="color: #009900;">&#40;</span>choice<span style="color: #339933;">,</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>k<span style="color: #339933;">==</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				fail<span style="color: #009900;">&#91;</span>F<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>x<span style="color: #339933;">;</span>
				F<span style="color: #339933;">++;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #009900;">&#123;</span>
				success<span style="color: #009900;">&#91;</span>T<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>x<span style="color: #339933;">;</span>
				T<span style="color: #339933;">++;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>F<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
			k<span style="color: #339933;">=</span>CaseChoice<span style="color: #009900;">&#40;</span>choice<span style="color: #339933;">,</span>fail<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		dwEnd<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		runtime<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>dwEnd<span style="color: #339933;">-</span>dwStart<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>F<span style="color: #339933;">;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>     查找了%d个数的数组，该种查找算法的平均查找失败时间是：%lf ms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>ListSize<span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>T<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
			k<span style="color: #339933;">=</span>CaseChoice<span style="color: #009900;">&#40;</span>choice<span style="color: #339933;">,</span>success<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		dwEnd<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		runtime<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">double</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>dwEnd<span style="color: #339933;">-</span>dwStart<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>T<span style="color: #339933;">;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>     查找了%d个数的数组，该种查找算法的平均查找成功时间是：%lf ms<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>ListSize<span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>choice<span style="color: #339933;">!=</span><span style="color: #0000dd;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #993333;">int</span> SeqSearch<span style="color: #009900;">&#40;</span>RecordList l<span style="color: #339933;">,</span>KeyType k<span style="color: #009900;">&#41;</span>
<span style="color: #808080; font-style: italic;">/*在顺序表l中顺序查找其关键字等于k的元素，若找到，则函数值为该元素在表中的位置，否则为0*/</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
	l.<span style="color: #202020;">r</span><span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>k<span style="color: #339933;">;</span>
	i<span style="color: #339933;">=</span>l.<span style="color: #202020;">Length</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>l.<span style="color: #202020;">r</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">!=</span>k<span style="color: #009900;">&#41;</span>
		i<span style="color: #339933;">--;</span>
	<span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>   <span style="color: #666666; font-style: italic;">//顺序查找</span>
&nbsp;
<span style="color: #993333;">void</span> InSort<span style="color: #009900;">&#40;</span>RecordList <span style="color: #339933;">*</span>l<span style="color: #339933;">,</span><span style="color: #993333;">int</span> length<span style="color: #009900;">&#41;</span>
<span style="color: #808080; font-style: italic;">/* 对记录数组r做直接插入排序，length为数组中待排序记录的数目*/</span><span style="color: #666666; font-style: italic;">//直接插入排序</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span>j<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span>length<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		l<span style="color: #339933;">-&gt;</span>r<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>l<span style="color: #339933;">-&gt;</span>r<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//将待插入记录存放到监视哨r[0]中</span>
		j<span style="color: #339933;">=</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>l<span style="color: #339933;">-&gt;</span>r<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span>l<span style="color: #339933;">-&gt;</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #808080; font-style: italic;">/* 寻找插入位置 */</span>
		<span style="color: #009900;">&#123;</span>
			l<span style="color: #339933;">-&gt;</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span> l<span style="color: #339933;">-&gt;</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			j<span style="color: #339933;">=</span>j<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		l<span style="color: #339933;">-&gt;</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>l<span style="color: #339933;">-&gt;</span>r<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*将待插入记录插入到已排序的序列中*/</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>   <span style="color: #666666; font-style: italic;">//插入排序</span>
&nbsp;
<span style="color: #993333;">int</span> BinSrch<span style="color: #009900;">&#40;</span>RecordList l<span style="color: #339933;">,</span>KeyType k<span style="color: #009900;">&#41;</span>
<span style="color: #808080; font-style: italic;">/*在有序表l中折半查找其关键字等于k的元素，若找到，则函数值为该元素在表中的位置*/</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> low<span style="color: #339933;">,</span>high<span style="color: #339933;">,</span>mid<span style="color: #339933;">;</span>
	low<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	high<span style="color: #339933;">=</span>l.<span style="color: #202020;">Length</span><span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*置区间初值*/</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>low<span style="color: #339933;">&lt;=</span>high<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		mid<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>low<span style="color: #339933;">+</span>high<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>k<span style="color: #339933;">==</span>l.<span style="color: #202020;">r</span><span style="color: #009900;">&#91;</span>mid<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span><span style="color: #009900;">&#40;</span>mid<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*找到待查元素*/</span>
		<span style="color: #b1b100;">else</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>k<span style="color: #339933;">&lt;</span>l.<span style="color: #202020;">r</span><span style="color: #009900;">&#91;</span>mid<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
				high<span style="color: #339933;">=</span>mid<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*未找到，则继续在前半区间进行查找*/</span>
			<span style="color: #b1b100;">else</span>
				low<span style="color: #339933;">=</span>mid<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*继续在后半区间进行查找*/</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>   <span style="color: #666666; font-style: italic;">//折半查找</span>
&nbsp;
<span style="color: #993333;">void</span> InsertBST<span style="color: #009900;">&#40;</span>BSTree <span style="color: #339933;">*</span>bst<span style="color: #339933;">,</span>KeyType x<span style="color: #009900;">&#41;</span>
<span style="color: #808080; font-style: italic;">/*若在二叉排序树中不存在关键字等于key的元素，插入该元素*/</span>
<span style="color: #009900;">&#123;</span>
	BSTree s<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>bst<span style="color: #339933;">==</span>NULL<span style="color: #009900;">&#41;</span><span style="color: #808080; font-style: italic;">/*递归结束条件*/</span>
	<span style="color: #009900;">&#123;</span>
		s<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>BSTree<span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>BSTNode<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*申请新的结点s*/</span>
		s<span style="color: #339933;">-&gt;</span>key<span style="color: #339933;">=</span>x<span style="color: #339933;">;</span>
		s<span style="color: #339933;">-&gt;</span>lchild<span style="color: #339933;">=</span>NULL<span style="color: #339933;">;</span> 
		s<span style="color: #339933;">-&gt;</span>rchild<span style="color: #339933;">=</span>NULL<span style="color: #339933;">;</span>
		<span style="color: #339933;">*</span>bst<span style="color: #339933;">=</span>s<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> 
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">&lt;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>bst<span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>key<span style="color: #009900;">&#41;</span>
			InsertBST<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>bst<span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>lchild<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #808080; font-style: italic;">/*将s插入左子树*/</span>
		<span style="color: #b1b100;">else</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>bst<span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>key<span style="color: #009900;">&#41;</span>
				InsertBST<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">*</span>bst<span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>rchild<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/*将s插入右子树*/</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> CreateBST<span style="color: #009900;">&#40;</span>BSTree <span style="color: #339933;">*</span>bst<span style="color: #339933;">,</span>RecordList list<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
	<span style="color: #339933;">*</span>bst <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span>ListSize<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		InsertBST<span style="color: #009900;">&#40;</span>bst<span style="color: #339933;">,</span>list.<span style="color: #202020;">r</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">int</span> SearchBST<span style="color: #009900;">&#40;</span>BSTree bst<span style="color: #339933;">,</span>KeyType key<span style="color: #009900;">&#41;</span><span style="color: #808080; font-style: italic;">/*返回1成功，返回0失败*/</span>
<span style="color: #009900;">&#123;</span>
	BSTree q<span style="color: #339933;">;</span>
	q<span style="color: #339933;">=</span>bst<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>q<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>q<span style="color: #339933;">-&gt;</span>key<span style="color: #339933;">==</span>key<span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>q<span style="color: #339933;">-&gt;</span>key<span style="color: #339933;">&gt;</span>key<span style="color: #009900;">&#41;</span>
			q<span style="color: #339933;">=</span>q<span style="color: #339933;">-&gt;</span>lchild<span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span>
			q<span style="color: #339933;">=</span>q<span style="color: #339933;">-&gt;</span>rchild<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>   <span style="color: #666666; font-style: italic;">//二叉查找</span>
&nbsp;
<span style="color: #993333;">int</span> CreatIndex<span style="color: #009900;">&#40;</span>Dexlist dexlist<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>Index index<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>RecordList list<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> m<span style="color: #339933;">,</span>n<span style="color: #339933;">,</span>i<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> number<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span><span style="color: #0000dd;">10</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		index<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #339933;">=</span><span style="color: #0000dd;">1000</span><span style="color: #339933;">*</span>i<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span><span style="color: #0000dd;">10</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		number<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	index<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">link</span><span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>m<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>m<span style="color: #339933;">&lt;=</span>ListSize<span style="color: #339933;">;</span>m<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>list.<span style="color: #202020;">r</span><span style="color: #009900;">&#91;</span>m<span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span>index<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">&lt;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			i<span style="color: #339933;">++;</span>
		number<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">++;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>n<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>n<span style="color: #339933;">&lt;</span><span style="color: #0000dd;">10</span><span style="color: #339933;">;</span>n<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		index<span style="color: #009900;">&#91;</span>n<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">link</span><span style="color: #339933;">=</span>index<span style="color: #009900;">&#91;</span>n<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">link</span><span style="color: #339933;">+</span>number<span style="color: #009900;">&#91;</span>n<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>m<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>m<span style="color: #339933;">&lt;=</span>ListSize<span style="color: #339933;">;</span>m<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>list.<span style="color: #202020;">r</span><span style="color: #009900;">&#91;</span>m<span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span>index<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">&lt;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			i<span style="color: #339933;">++;</span>
		n<span style="color: #339933;">=</span>index<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">link</span><span style="color: #339933;">;</span>
		dexlist<span style="color: #009900;">&#91;</span>n<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #339933;">=</span>list.<span style="color: #202020;">r</span><span style="color: #009900;">&#91;</span>m<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		index<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">link</span><span style="color: #339933;">++;</span>
	<span style="color: #009900;">&#125;</span>
	m<span style="color: #339933;">--;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>m<span style="color: #339933;">==</span>ListSize<span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">int</span> IndexSearch<span style="color: #009900;">&#40;</span>Dexlist r<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>Index index<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> key<span style="color: #009900;">&#41;</span><span style="color: #666666; font-style: italic;">//key 为给定值，索引表为index[1]..index[b]    </span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span>j<span style="color: #339933;">;</span>
	i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>key<span style="color: #339933;">&gt;</span>index<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">&lt;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		i<span style="color: #339933;">++;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">&gt;=</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">&gt;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span>
		j<span style="color: #339933;">=</span>index<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">link</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span>
		j<span style="color: #339933;">=</span>index<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #202020;">link</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">&lt;</span>ListSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>key<span style="color: #339933;">!=</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&amp;&amp;</span><span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #339933;">&lt;=</span>index<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
			j<span style="color: #339933;">++;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>key<span style="color: #339933;">==</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>   <span style="color: #666666; font-style: italic;">//索引查找</span>
&nbsp;
<span style="color: #993333;">int</span> Hash<span style="color: #009900;">&#40;</span>KeyType k<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> h<span style="color: #339933;">;</span>
	h<span style="color: #339933;">=</span>k<span style="color: #339933;">%</span><span style="color: #009900;">&#40;</span>TableSize<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> h<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> CreatHashTable<span style="color: #009900;">&#40;</span>RecordList l<span style="color: #339933;">,</span><span style="color: #993333;">int</span> SIZE<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span>j<span style="color: #339933;">,</span>hj<span style="color: #339933;">,</span>t<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> p<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>SIZE<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		hashtable<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #339933;">=</span>NULLKEY<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span>ListSize<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		fflush<span style="color: #009900;">&#40;</span>stdin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		p<span style="color: #339933;">=</span>l.<span style="color: #202020;">r</span><span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		j<span style="color: #339933;">=</span>Hash<span style="color: #009900;">&#40;</span>p<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>hashtable<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #339933;">==</span>NULLKEY<span style="color: #009900;">&#41;</span>
			hashtable<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #339933;">=</span>p<span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>t<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>t<span style="color: #339933;">&lt;</span>SIZE<span style="color: #339933;">;</span>t<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				hj<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">+</span>t<span style="color: #009900;">&#41;</span><span style="color: #339933;">%</span><span style="color: #009900;">&#40;</span>SIZE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>hashtable<span style="color: #009900;">&#91;</span>hj<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #339933;">==</span>NULLKEY<span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					hashtable<span style="color: #009900;">&#91;</span>hj<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #339933;">=</span>p<span style="color: #339933;">;</span>
					t<span style="color: #339933;">=</span>SIZE<span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">int</span> HashSearch<span style="color: #009900;">&#40;</span>HashTable ht<span style="color: #339933;">,</span> KeyType K<span style="color: #339933;">,</span><span style="color: #993333;">int</span> SIZE<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> h0<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> hi<span style="color: #339933;">;</span>
	h0<span style="color: #339933;">=</span>Hash<span style="color: #009900;">&#40;</span>K<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>ht<span style="color: #009900;">&#91;</span>h0<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #339933;">==</span>NULLKEY<span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>ht<span style="color: #009900;">&#91;</span>h0<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #339933;">==</span>K<span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span><span style="color: #808080; font-style: italic;">/* 用线性探测再散列解决冲突 */</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>SIZE<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				hi<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>h0<span style="color: #339933;">+</span>i<span style="color: #009900;">&#41;</span><span style="color: #339933;">%</span>SIZE<span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>ht<span style="color: #009900;">&#91;</span>hi<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #339933;">==</span>NULLKEY<span style="color: #009900;">&#41;</span>
					<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">else</span>
					<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>ht<span style="color: #009900;">&#91;</span>hi<span style="color: #009900;">&#93;</span>.<span style="color: #202020;">key</span><span style="color: #339933;">==</span>K<span style="color: #009900;">&#41;</span>
						<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>   <span style="color: #666666; font-style: italic;">//开地址法哈希查找</span>
&nbsp;
<span style="color: #993333;">void</span> InitHash<span style="color: #009900;">&#40;</span>Node <span style="color: #339933;">**</span>A<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span><span style="color: #0000dd;">15</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		A<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>Node <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>Node<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		A<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
		A<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">=</span>NULL<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> InsertHash<span style="color: #009900;">&#40;</span>Node <span style="color: #339933;">**</span>Q<span style="color: #339933;">,</span><span style="color: #993333;">int</span> value<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> key<span style="color: #339933;">;</span>
	Node <span style="color: #339933;">*</span>p<span style="color: #339933;">,*</span>q<span style="color: #339933;">;</span>
	key<span style="color: #339933;">=</span>value<span style="color: #339933;">%</span><span style="color:#800080;">15</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>Q<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">!=</span>NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		p<span style="color: #339933;">=</span>Q<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>p<span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">!=</span>NULL<span style="color: #009900;">&#41;</span>
			p<span style="color: #339933;">=</span>p<span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">;</span>
		q<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>Node <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>Node<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		q<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">=</span>value<span style="color: #339933;">;</span>
		q<span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">=</span>NULL<span style="color: #339933;">;</span>
		p<span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">=</span>q<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		q<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>Node <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>Node<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		q<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">=</span>value<span style="color: #339933;">;</span>
		q<span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">=</span>NULL<span style="color: #339933;">;</span>
		Q<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">=</span>q<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">int</span> SearchHash<span style="color: #009900;">&#40;</span>Node <span style="color: #339933;">**</span>Q<span style="color: #339933;">,</span><span style="color: #993333;">int</span> value<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> key<span style="color: #339933;">;</span>
	Node <span style="color: #339933;">*</span>p<span style="color: #339933;">;</span>
	key<span style="color: #339933;">=</span>value<span style="color: #339933;">%</span><span style="color:#800080;">15</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>Q<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">==</span>NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		p<span style="color: #339933;">=</span>Q<span style="color: #009900;">&#91;</span>key<span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>p<span style="color: #339933;">!=</span>NULL<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>p<span style="color: #339933;">-&gt;</span>data<span style="color: #339933;">==</span>value<span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
			p<span style="color: #339933;">=</span>p<span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>     <span style="color: #666666; font-style: italic;">//拉链法哈希查找</span></pre></div></div>

<p>　　可能大家已经发现了，为了实现上述思路，并把代码冗余量减少，我把各个函数的引用又单独放到了一个CaseChoice函数里，主函数就负责循环。虽然简洁了不少，但如此一来有个问题：就是计时的时候把查找之前的一些动作都计算进去了，比如折半查找中包含了插入排序、二叉树查找包含了树的建立、哈希查找包含了建立哈希表的过程等等，应该有比较好的解决方法，但实在不想深究，于是乎放弃了 <img src='https://terence2008.info/wp-includes/images/smilies/icon_mrgreen.gif' alt=':mrgreen:' class='wp-smiley' />  但不管怎么说，把运行后的数据结果处理成图表后明显感觉到了各个算法间效率的差异。</p>
<p><a href="http://terence2008.info/wp-content/uploads/2010/05/finding-compare.jpg" rel="lightbox[367]" title="各个查找算法效率比较"><img class="alignnone size-medium wp-image-368" title="各个查找算法效率比较" src="http://terence2008.info/wp-content/uploads/2010/05/finding-compare-300x173.jpg" alt="" width="300" height="173" /></a></p>
<p>　　顺便提一句，数据结构课程设计（基于<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/c" title="查看 C 的全部文章">C</a></span>语言）终于随着本次作业的完成而结束了，痛苦啊，如果再给我一个题目的话我要疯了。。。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="六种查找算法效率比较" href="http://terence2008.info/archives/finding_compare.html">《六种查找算法效率比较》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/sorting_compare.html" title="八种排序算法效率比较">八种排序算法效率比较</a> (6)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/finding_compare.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>巧用Google AdSense赚美元</title>
		<link>http://terence2008.info/archives/google-adsense.html</link>
		<comments>http://terence2008.info/archives/google-adsense.html#comments</comments>
		<pubDate>Thu, 29 Apr 2010 09:22:28 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[网络技术]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[博客]]></category>
		<category><![CDATA[广告]]></category>
		<category><![CDATA[网页]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=361</guid>
		<description><![CDATA[<p>　　当今<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/google" title="查看 Google 的全部文章">Google</a></span>的AdSense可谓是全球所有网站中展示最多的代码了，原因很简单——可靠的内容提供商+较高的佣金收入。</p>
<p>　　根据<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/google" title="查看 Google 的全部文章">Google</a></span>网站的解释：<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/google" title="查看 Google 的全部文章">Google</a></span> AdSense是一个快速简便的网上赚钱方法，可以让具有一定访问量规模的网站发布商为他们的网站展示与网站内容相关的Google<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e5%b9%bf%e5%91%8a" title="查看 广告 的全部文章">广告</a></span>并将网站流量转化为收入。Google AdSense是网络会员联盟的一种形式，如果一个网站加入Google AdSense，即成为Google的内容发布商，作为内容发布商可以在自己网站上显示Google关键词<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e5%b9%bf%e5%91%8a" title="查看 广告 的全部文章">广告</a></span>，Google根据会员网站上显示的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e5%b9%bf%e5%91%8a" title="查看 广告 的全部文章">广告</a></span>被点击的次数支付佣金，当某个月底佣金累计达到100美元时即可向用户支付广告点击佣金。如果你拥有自己的网站并有一定的访问量，均可免费申请加入Google AdSense，无论网站是个人的还是商业的。当然并不是每个网站都能获准加入，例如提供MP3下载、色情、暴力等内容的网站将不会被许可加盟AdSense。</p>
<p>　　当然，对于采取作弊手段获取广告佣金或者违反Google Adsense规则的联盟网站，即使成为Google Adsense内容发布商也无法拿到Google的广告佣金，这些Google Adsense内容发布商网站的帐号很可能会被删除。Google Adsense内容发布商帐号被取消的原因通常是由于网站将Google广告以不适当的方式放置在不适当的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%bd%91%e9%a1%b5" title="查看 网页 的全部文章">网页</a></span>内容或位置、对用户造成误导性点击、人为的点击欺诈，以及采用堆砌关键词、隐藏性文字等搜索引擎优化作弊手段。</p>
<p>　　Google广告分为：AdSense内容广告、Google搜索联盟、AdSense搜索广告、AdSense for Feeds、AdSense 移动广告五种。一般基本上只采用前三种模式，但根据前人经验，做Google搜索联盟是利润最高的，最近本人看过自己的AdSense收入报告，发现搜索联盟有效点击的收入单价最高竟然有70$！也就是说点3次广告就有1$了 <img src='https://terence2008.info/wp-includes/images/smilies/icon_mrgreen.gif' alt=':mrgreen:' class='wp-smiley' /> </p>
<p><a href="http://terence2008.info/wp-content/uploads/2010/04/adsense1.jpg" rel="lightbox[361]" title="Google AdSense收益"><img class="alignnone size-medium wp-image-363" title="Google AdSense收益" src="http://terence2008.info/wp-content/uploads/2010/04/adsense1-300x132.jpg" alt="" width="300" height="132" /></a><a href="http://terence2008.info/wp-content/uploads/2010/04/adsense2.jpg" rel="lightbox[361]" title="Google搜索联盟收益"><img class="alignnone size-medium wp-image-364" title="Google搜索联盟收益" src="http://terence2008.info/wp-content/uploads/2010/04/adsense2-300x125.jpg" alt="" width="300" height="132" /></a></p>
<p>　　下面我就介绍下AdSense搜索联盟赚钱原理：<br />
 1、将Google提供的代码放到网站上，会显示一个Google搜索框，并且下面有数个关键词。<br />
 2、当用户通过Google搜索框搜索，并点击搜索结果中显示在右侧或是左侧上面的广告时，将会产生收入。比如，搜索“赚钱”，结果中将会出现很多与赚钱相关的广告。当用户点击这些广告去查看广告网站时，广告主将会向Google支付广告费，而因为是我们帮助Google拓展搜索渠道的，所以Google也会分取一部分给我们。<br />
 3、然而绝大部分关键字是不匹配广告的，只有那些商业性较强的词，比如：赚钱、美容、减肥……才会出现广告，虽然这个数量已经很庞大，但比较人们可能搜索的词而言，实在是九牛一毛……<br />
比如有可能1000次搜索，有广告的词只有10个，而这10个有广告的词中，可能只有一个广告点击，只有广告被点击后，我们才会获取收入。<br />
 4、Google为了推广Google搜索联盟，所以推出了“推荐关键字”的做法，一般那些推荐的关键字，都是那些有广告的，在希望那些广告被点击的立场上看，Google与我们是站在一条线上的，这就引导用户直接点击那些关键字，进行搜索，简化了执行流程，也同样提升了广告被点击的次数。</p>
<p>　　其实算下来，真会去点你的广告的人实在不多，所以会有很多人想到作弊。Google是全世界最大的网络广告联盟，它的技术是首屈一指的，所以绝大部分作弊手段都逃不过他们的法眼。他们有一套系统在评测是否作弊，当某些数据出现不正常时，系统会自动发现，这时会介入人工调查，一般会把该账号K掉，同时没收之前全部收入，处罚措施是相当严格的。但不管怎样，变相的“作弊”又未尝不可，这里出现的漏洞就是——它是主要通过软件来调查的，只要各项数据正常，人工就不会来看，只要摸清一些规则，就可以“作弊”。</p>
<p>　　所以我们就要分析出Google系统一般会针对哪些规则非常严格：</p>
<p> 1、每个账号每月收入不超过200美金！<br />
Google会把老号（收过款的）及新号区分对待，作弊调查基本上都针对那些新号。新号一旦超过200美金，就会严格对待。如果收过款了，可以渐渐增加收入……这就是为什么很多作弊的人都要多账号操作的原因：一来分散风险；二来增加收入。<br />
 2、点击率<br />
点击率是指：广告点击量/搜索量。比如1000个搜索后，广告被点击了10次，这样点击率就是1%广告点击率过高，那肯定是要K号的。（比如10次搜索后，广告就被点击了8次，那样几乎肯定是作弊操作的）一般最好保持在10%以下，新号越低越好。超过20%，风险就是极高的。<br />
 3、广告点击的IP需要分散开来<br />
不可能所有的广告点击都是由少量IP点击的。<br />
 4、延长用户在广告主网站停留时间<br />
这点非常重要。如果用户点击了广告后，立马把它关掉，那么就认定为无效点击。无效点击一旦多的话，那Google会怀疑你是否在作弊。所以延长用户在广告主网站停留时间，是相当必要的，这也是Google判断是否作弊的重要因素。<br />
 5、禁止诱导点击<br />
不能诱导用户点击广告，包括欺骗或是非欺骗。比如，在网站上说：点击广告，送100元现金等等这类的话。一旦发现，肯定封号。除了不能在该网站上诱导外，Google的技术同样能查到用户来访的上一个网址。比如，你在A网上要求用户到B网上点击广告，那Google也是能查得到的。<br />
 6、其它<br />
Google对于作弊规则从来是不公开的，因为它知道道高一尺、魔高一丈，只要规则公开就会有办法破解。但原则上，只要你的作弊方法近似于真实搜索，那样Google就没有理由认定你的作弊。</p>
<p>　　希望这篇文章能够让大家对Google的广告盈利模式有一个大致的了解，使你明白类似“hao123”之类的网站并不是一个不盈利的非商业网站。最后祝愿跟我一样开博的童鞋们能早日拿到从美国寄来的100$支票哈，虽然我知道这是个很漫长的过程~~</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="巧用Google AdSense赚美元" href="http://terence2008.info/archives/google-adsense.html">《巧用Google AdSense赚美元》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/thesis.html" title="浅谈不同浏览器地址栏中编码的差异">浅谈不同浏览器地址栏中编码的差异</a> (2)</li><li><a href="http://terence2008.info/archives/013.html" title="Google阅读器里RSS的显示问题">Google阅读器里RSS的显示问题</a> (0)</li><li><a href="http://terence2008.info/archives/ajaxswing.html" title="AjaxSwing4.4.0授权码">AjaxSwing4.4.0授权码</a> (2)</li><li><a href="http://terence2008.info/archives/tinymce-firefox.html" title="TinyMCE编辑器对FireFox的兼容不太好">TinyMCE编辑器对FireFox的兼容不太好</a> (1)</li><li><a href="http://terence2008.info/archives/010.html" title="网页中连续字符手动换行的方法">网页中连续字符手动换行的方法</a> (0)</li><li><a href="http://terence2008.info/archives/003.html" title="推荐一个博客">推荐一个博客</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/google-adsense.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TinyMCE编辑器对FireFox的兼容不太好</title>
		<link>http://terence2008.info/archives/tinymce-firefox.html</link>
		<comments>http://terence2008.info/archives/tinymce-firefox.html#comments</comments>
		<pubDate>Tue, 27 Apr 2010 11:44:39 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[网络技术]]></category>
		<category><![CDATA[FireFox]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[插件]]></category>
		<category><![CDATA[网页]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=359</guid>
		<description><![CDATA[<p>　　<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/wordpress" title="查看 WordPress 的全部文章">WordPress</a></span>自带的在线编辑器TinyMCE刚开始用的时候觉得功能实在过于单薄，几乎想要放弃转投向Windows Live Writer之类的基于XML-RPC或者Atom发布协议的本地编辑器。可自从有了这个叫TinyMCE-Advanced的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%8f%92%e4%bb%b6" title="查看 插件 的全部文章">插件</a></span>，使自带的编辑器再也不是鸡肋了，基本上可以实现像Word里面的大部分排版，包括制表。</p>
<p>　　可前几天发现TinyMCE在<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/firefox" title="查看 FireFox 的全部文章">FireFox</a></span>下编辑有个问题，每段的开头要缩进的话，一般我们会打上几个空格来实现。可在<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/firefox" title="查看 FireFox 的全部文章">FireFox</a></span>下发布文章后，段落开头的空格就自动消失了，但在所有版本的IE下都是正常的。之前还以为是<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%8f%92%e4%bb%b6" title="查看 插件 的全部文章">插件</a></span>冲突的问题，不过之后的实验证明这不是个例，搜索“TinyMCE+FireFox”能找到一堆同样的问题，看来这是个历史遗留难题呀。。。究其原因的话也难怪，<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/wordpress" title="查看 WordPress 的全部文章">WordPress</a></span>本来就不是国人开发，老外写文章貌似就没有开头空格的习惯，所以凭什么人家给你修改这个缺陷呢？</p>
<p>　　既然TinyMCE太过于自作聪明，我们就只能在源代码中下手了。解决方法很简单，文章编辑完后切换到Html模式下，在每段开头添加两个全角的空格，有两点需要注意：1.必须要全角的空格；2.添加完后就不能再切换回“可视化”下，因为这样做会使你刚才添加的空格又被“聪明”地去除了。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="TinyMCE编辑器对FireFox的兼容不太好" href="http://terence2008.info/archives/tinymce-firefox.html">《TinyMCE编辑器对FireFox的兼容不太好》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/my-plugins.html" title="我正在使用的插件列表">我正在使用的插件列表</a> (1)</li><li><a href="http://terence2008.info/archives/013.html" title="Google阅读器里RSS的显示问题">Google阅读器里RSS的显示问题</a> (0)</li><li><a href="http://terence2008.info/archives/010.html" title="网页中连续字符手动换行的方法">网页中连续字符手动换行的方法</a> (0)</li><li><a href="http://terence2008.info/archives/ajaxswing.html" title="AjaxSwing4.4.0授权码">AjaxSwing4.4.0授权码</a> (2)</li><li><a href="http://terence2008.info/archives/wordpress_database_optimize.html" title="WordPress数据库的一处性能优化">WordPress数据库的一处性能优化</a> (1)</li><li><a href="http://terence2008.info/archives/blog_maintenance.html" title="博客维护日记">博客维护日记</a> (0)</li><li><a href="http://terence2008.info/archives/thesis.html" title="浅谈不同浏览器地址栏中编码的差异">浅谈不同浏览器地址栏中编码的差异</a> (2)</li><li><a href="http://terence2008.info/archives/google-adsense.html" title="巧用Google AdSense赚美元">巧用Google AdSense赚美元</a> (1)</li><li><a href="http://terence2008.info/archives/change-space.html" title="换空间了">换空间了</a> (1)</li><li><a href="http://terence2008.info/archives/009.html" title="让flash植入代码符合xhtml标准">让flash植入代码符合xhtml标准</a> (1)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/tinymce-firefox.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>鹦鹉版 杰克逊舞</title>
		<link>http://terence2008.info/archives/bird-dancing.html</link>
		<comments>http://terence2008.info/archives/bird-dancing.html#comments</comments>
		<pubDate>Sat, 24 Apr 2010 13:33:40 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[视频]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=355</guid>
		<description><![CDATA[<p>      刚开始还以为是人在控制这个鸟呢，这鸟太有乐感了。。。。</p>
<p>
<object type="application/x-shockwave-flash" width="480" height="400" data="http://player.youku.com/player.php/sid/XMTEyOTk1MTE2/v.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://player.youku.com/player.php/sid/XMTEyOTk1MTE2/v.swf" /></object></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="鹦鹉版 杰克逊舞" href="http://terence2008.info/archives/bird-dancing.html">《鹦鹉版 杰克逊舞》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/android-iphone-girl.html" title="智能手机的另一大功能——造星">智能手机的另一大功能——造星</a> (2)</li><li><a href="http://terence2008.info/archives/i-expect.html" title="我期待……">我期待……</a> (2)</li><li><a href="http://terence2008.info/archives/happy-mothers-day.html" title="母亲节——妈妈快乐！">母亲节——妈妈快乐！</a> (1)</li><li><a href="http://terence2008.info/archives/mario.html" title="没钱没车没房也想当英雄救公主？">没钱没车没房也想当英雄救公主？</a> (0)</li><li><a href="http://terence2008.info/archives/a-song.html" title="一首歌 两个人">一首歌 两个人</a> (0)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/014.html" title="天衣无缝的视频剪辑">天衣无缝的视频剪辑</a> (2)</li><li><a href="http://terence2008.info/archives/012.html" title="如果我是个男孩要带女朋友回家">如果我是个男孩要带女朋友回家</a> (0)</li><li><a href="http://terence2008.info/archives/011.html" title="朝鲜大妈，我被你吓到了= =！">朝鲜大妈，我被你吓到了= =！</a> (0)</li><li><a href="http://terence2008.info/archives/008.html" title="信春哥 死后四次原地满血复活">信春哥 死后四次原地满血复活</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/bird-dancing.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>没钱没车没房也想当英雄救公主？</title>
		<link>http://terence2008.info/archives/mario.html</link>
		<comments>http://terence2008.info/archives/mario.html#comments</comments>
		<pubDate>Thu, 22 Apr 2010 14:28:37 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[视频]]></category>
		<category><![CDATA[转载]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=353</guid>
		<description><![CDATA[<p>      以超级玛丽游戏式的展现手法，把当今社会上随着结婚而带来的种种问题暴露无遗，一句话：钱不是万能滴，但没有钱是万万不能滴~~但不管怎么说，这是个很不错的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%a7%86%e9%a2%91" title="查看 视频 的全部文章">视频</a></span>哦 <img src='https://terence2008.info/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' />  </p>
<p> <br />
<object type="application/x-shockwave-flash" width="480" height="400" data="http://player.youku.com/player.php/sid/XMTY1NzQxMDQw/v.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://player.youku.com/player.php/sid/XMTY1NzQxMDQw/v.swf" /></object></p>
<blockquote><div> 　&raquo; <span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%bd%ac%e8%bd%bd" title="查看 转载 的全部文章">转载</a></span>请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="没钱没车没房也想当英雄救公主？" href="http://terence2008.info/archives/mario.html">《没钱没车没房也想当英雄救公主？》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/007.html" title="李献计历险记">李献计历险记</a> (1)</li><li><a href="http://terence2008.info/archives/android-iphone-girl.html" title="智能手机的另一大功能——造星">智能手机的另一大功能——造星</a> (2)</li><li><a href="http://terence2008.info/archives/i-expect.html" title="我期待……">我期待……</a> (2)</li><li><a href="http://terence2008.info/archives/happy-mothers-day.html" title="母亲节——妈妈快乐！">母亲节——妈妈快乐！</a> (1)</li><li><a href="http://terence2008.info/archives/bird-dancing.html" title="鹦鹉版 杰克逊舞">鹦鹉版 杰克逊舞</a> (0)</li><li><a href="http://terence2008.info/archives/a-song.html" title="一首歌 两个人">一首歌 两个人</a> (0)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/014.html" title="天衣无缝的视频剪辑">天衣无缝的视频剪辑</a> (2)</li><li><a href="http://terence2008.info/archives/012.html" title="如果我是个男孩要带女朋友回家">如果我是个男孩要带女朋友回家</a> (0)</li><li><a href="http://terence2008.info/archives/011.html" title="朝鲜大妈，我被你吓到了= =！">朝鲜大妈，我被你吓到了= =！</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/mario.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>一首歌 两个人</title>
		<link>http://terence2008.info/archives/a-song.html</link>
		<comments>http://terence2008.info/archives/a-song.html#comments</comments>
		<pubDate>Sat, 17 Apr 2010 15:22:01 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[视频]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=351</guid>
		<description><![CDATA[<p>      对这个<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%a7%86%e9%a2%91" title="查看 视频 的全部文章">视频</a></span>印象很深刻，清明节去台州临海玩，晚上看江苏卫视的非诚勿扰，这个人上场后直接点名说喜欢台上的一个女孩，他本身的职业是歌曲合成创作，所以他用自己的专长为她写了一首歌并唱给了她听，被感动了。鉴定结果：不会浪漫的人不经意间也能创造出浪漫。</p>
<p>
<object type="application/x-shockwave-flash" width="480" height="400" data="http://player.youku.com/player.php/sid/XMTYyNzUxMTgw/v.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://player.youku.com/player.php/sid/XMTYyNzUxMTgw/v.swf" /></object></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="一首歌 两个人" href="http://terence2008.info/archives/a-song.html">《一首歌 两个人》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/android-iphone-girl.html" title="智能手机的另一大功能——造星">智能手机的另一大功能——造星</a> (2)</li><li><a href="http://terence2008.info/archives/i-expect.html" title="我期待……">我期待……</a> (2)</li><li><a href="http://terence2008.info/archives/happy-mothers-day.html" title="母亲节——妈妈快乐！">母亲节——妈妈快乐！</a> (1)</li><li><a href="http://terence2008.info/archives/bird-dancing.html" title="鹦鹉版 杰克逊舞">鹦鹉版 杰克逊舞</a> (0)</li><li><a href="http://terence2008.info/archives/mario.html" title="没钱没车没房也想当英雄救公主？">没钱没车没房也想当英雄救公主？</a> (0)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/014.html" title="天衣无缝的视频剪辑">天衣无缝的视频剪辑</a> (2)</li><li><a href="http://terence2008.info/archives/012.html" title="如果我是个男孩要带女朋友回家">如果我是个男孩要带女朋友回家</a> (0)</li><li><a href="http://terence2008.info/archives/011.html" title="朝鲜大妈，我被你吓到了= =！">朝鲜大妈，我被你吓到了= =！</a> (0)</li><li><a href="http://terence2008.info/archives/008.html" title="信春哥 死后四次原地满血复活">信春哥 死后四次原地满血复活</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/a-song.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>我正在使用的插件列表</title>
		<link>http://terence2008.info/archives/my-plugins.html</link>
		<comments>http://terence2008.info/archives/my-plugins.html#comments</comments>
		<pubDate>Fri, 16 Apr 2010 16:48:12 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[网络技术]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[插件]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=341</guid>
		<description><![CDATA[<p>      用<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/wordpress" title="查看 WordPress 的全部文章">WordPress</a></span>的时间差不多也有4个月了，感觉开源的东西就是很好很强大，很多功能都可以用各种各样的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%8f%92%e4%bb%b6" title="查看 插件 的全部文章">插件</a></span>来实现，下面就来展示下现在我所正在使用的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%8f%92%e4%bb%b6" title="查看 插件 的全部文章">插件</a></span>。</p>
<p>      算下来到现在竟然已经开启了30个之多！虽然这势必会影响到网站的性能，但作为菜鸟来说，与其手动去修改繁琐的主题代码来实现相应的功能，不如加载<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%8f%92%e4%bb%b6" title="查看 插件 的全部文章">插件</a></span>一劳永逸地实现个性化的需求，而且还可以不断地从插件作者那儿获得功能更新。当初看中<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/wordpress" title="查看 WordPress 的全部文章">WordPress</a></span>作为博客程序的原因就是因为他有着庞大且丰富的插件资源，就像操作系统，有些Linux的功能已经和Windows相当接近了，但还是很少人去把它作为自己的主操作系统，就是因为没有更多更好的软件去支持它的平台。</p>
<p>      以下插件列表已经做好了对应的下载链接，如果需要的话直接鼠标猛击就可以了 <img src='https://terence2008.info/wp-includes/images/smilies/icon_smile.gif' alt=':smile:' class='wp-smiley' />  </p>
<table style="width: 600px;" border="0">
<thead>
<tr align="center" valign="middle">
<td> </td>
<td><strong>名称</strong></td>
<td><strong>说明</strong></td>
</tr>
</thead>
<tbody>
<tr valign="middle">
<td align="center" valign="middle">1</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/adsense-integrator/" target="_blank">AdSense Integrator</a></td>
<td align="left" valign="middle">一款很不错的广告插件，可以在网页的任意位置摆放广告代码，最多可以在同个页面放置9处广告</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">2</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/all-in-one-seo-pack/" target="_blank">All in One SEO Pack</a></td>
<td align="left" valign="middle">老牌的seo插件，用这个插件就可以实现<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/wordpress" title="查看 WordPress 的全部文章">WordPress</a></span>的整体优化</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">3</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/chinese-word-count/" target="_blank">Chinese Word Count</a></td>
<td align="left" valign="middle">用自带的编辑器写文章的时候，中文字数统计不怎么正确，可以使用这个插件来修正</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">4</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/clean-archives-reloaded/" target="_blank">Clean Archives Reloaded</a></td>
<td align="left" valign="middle">存档页的自动生成，默认可以展开和折叠，显示存档列表并显示当月存档数字和文章评论数字，基本的功能已经都具备了</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">5</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/daitui-service/" target="_blank">Daitui</a></td>
<td align="left" valign="middle">看到文章后面的那个分享按钮了吗？这就是此插件的功能，加入了中国流行的SNS网站</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">6</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/tags/download-counter" target="_blank">Download Counter</a></td>
<td align="left" valign="middle">一个比较简单的下载统计插件，还能设置简洁链接，起到隐藏真实链接作用</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">7</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/flash-mp3-player/" target="_blank">Flash MP3 Player JW2.3</a></td>
<td align="left" valign="middle">基于flash的MP3播放器，放在右侧栏目上，挺漂亮的，功能也强大</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">8</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/google-sitemap-generator/" target="_blank">Google XML Sitemaps</a></td>
<td align="left" valign="middle">官方推荐的插件，当你发表或修改博客内容后，它将为你的博客自动创建、更新Google Sitemap格式的XML，它支持所有的WordPress发表的内容，及自定义</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">9</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/lightbox-plus/" target="_blank">Lightbox Plus</a></td>
<td align="left" valign="middle">使图片采用灯箱效果展示，支持幻灯片播放，还有其他一些自定义功能</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">10</td>
<td align="left" valign="middle"><a href="http://onemansblog.com/2007/04/15/no-ping-wait-wordpress-plugin/" target="_blank">No Ping Wait</a></td>
<td align="left" valign="middle">无需等待后台ping back的时间</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">11</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/nospamnx/" target="_blank">NoSpamNX</a></td>
<td align="left" valign="middle">反垃圾评论插件，它采用添加隐藏表单项的方式来反垃圾，正常的评论用户是看不到的，只有垃圾评论机器人才会读到表单中的这个隐藏项，然后不管三七二十一的填上它提交，于是填上的全部被插件阻止</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">12</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/no-www/" target="_blank">No WWW</a></td>
<td align="left" valign="middle">让带www的域名自动301跳转到不带www的域名上来，有利于seo。其实还可以用rewrite重写规则来实现这个功能，但我的空间不支持，只能代码301跳转</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">13</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/one-click-plugin-updater/" target="_blank">One Click Plugin Updater</a></td>
<td align="left" valign="middle">能自动检测插件的更新，支持自动安装，还能在线安装存在于网络和本机上的插件和主题</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">14</td>
<td align="left" valign="middle"><a href="http://fairyfish.net/2008/07/07/super-image-plugin/" target="_blank">Super Image Plugin</a></td>
<td align="left" valign="middle">实现WordPress上传图片时自动增加水印</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">15</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/tinymce-advanced/" target="_blank">TinyMCE Advanced</a></td>
<td align="left" valign="middle">WordPress中自带的默认编辑器是TinyMCE，功能比较简单。有人添加了16个插件，形成了TinyMCE高级版，使在线编辑器不再成为鸡肋</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">16</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/wp-db-backup/" target="_blank">WordPress Database Backup</a></td>
<td align="left" valign="middle">自动定时备份数据库到指定的邮箱，为了数据安全，千万要记得备份啊！</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">17</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/wordpress-23-related-posts-plugin/" target="_blank">WordPress Related Posts</a></td>
<td align="left" valign="middle">相关日志插件，将相同tag的文章产生一个相关日志列表，并且可以把相关日志列表添加到Feed中，方便阅读</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">18</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/wordpress-thread-comment/" target="_blank">Wordpress Thread Comment</a></td>
<td align="left" valign="middle">用户可以对已有评论进行回复讨论,嵌套或成串显示相关讨论,无需对Wordpress和主题进行修改,支持AJAX，无需刷新整个页面即可留言,自动发送提醒留言已经回复的邮件</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">19</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/wp-cumulus/" target="_blank">WP-Cumulus</a></td>
<td align="left" valign="middle">用Flash+JS实现的超炫Wordpress标签云效果，但对中文支持不太好，需要另外下载swf文件</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">20</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/wp-mail-smtp/" target="_blank">WP-Mail-SMTP</a></td>
<td align="left" valign="middle">可以重设置php_mail()函数，使其可以用SMTP方式取代php_mail()来发送邮件。但注意，和Wordpress Thread Comment插件会有冲突，需要修改代码</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">21</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/wp-pagenavi/" target="_blank">WP-PageNavi</a></td>
<td align="left" valign="middle">分页插件，虽然WordPress自身也有这个功能，但是过于简单，只能翻至前后页，对读者来说会造成阅读障碍，安装这个之后就可以彻底解决这一问题</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">22</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/wp-postviews/" target="_blank">WP-PostViews</a></td>
<td align="left" valign="middle">用来统计一篇文章阅读次数，还可以在侧边栏实现显示阅读次数最多的文章或者页面、某分类下阅读次数最多的文章等</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">23</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/wp-recentcomments/" target="_blank">WP-RecentComments</a></td>
<td align="left" valign="middle">在WordPress侧边栏显示最新评论，可以限制显示评论的数量，设置评论摘要的最大长度等，支持AJAX，通过点击分页按钮来查看新旧评论</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">24</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/wp-syntax/" target="_blank">WP-Syntax</a></td>
<td align="left" valign="middle">使代码高亮的插件，可以让你的程序代码更容易阅读</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">25</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/wp-t-wap/" target="_blank">WP-T-Wap</a></td>
<td align="left" valign="middle">用于实现网站的手机浏览与管理功能的插件，其最大功能是能够管理日志和留言</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">26</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/wp-useragent/" target="_blank">WP-UserAgent</a></td>
<td align="left" valign="middle">自动检测并以图标形式显示博客里的留言者的操作系统和浏览器，需要适当修改主题的代码</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">27</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/wp-utf8-excerpt/" target="_blank">wp-utf8-excerpt</a></td>
<td align="left" valign="middle">为使用多字节语言（如中文）的用户提供更好的摘要算法，以解决Wordpress默认摘要算法只考虑西方语言的不足。此插件产生的摘要可保留原文中的html标签</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">28</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/wp-grins-lite/" target="_blank">WP Grins Lite</a></td>
<td align="left" valign="middle">一款在编辑框框下方插入表情选择的插件</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">29</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/rejected-wp-keyword-link-rejected/" target="_blank">WP Keyword Link</a></td>
<td align="left" valign="middle">为博客添加关键词的链接，支持自动和手动的内链和外链，有利于SEO，完美支持中英文关键词</td>
</tr>
<tr valign="middle">
<td align="center" valign="middle">30</td>
<td align="left" valign="middle"><a href="http://wordpress.org/extend/plugins/wp-super-cache/" target="_blank">WP Super Cache</a></td>
<td align="left" valign="middle">有名的WordPress缓存插件，可以减少你的博客对主机资源的占用，对于访问量高的博客来说，这是一个非常有用的插件，不过前提是你的博客url已经伪静态化</td>
</tr>
</tbody>
</table>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="我正在使用的插件列表" href="http://terence2008.info/archives/my-plugins.html">《我正在使用的插件列表》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/tinymce-firefox.html" title="TinyMCE编辑器对FireFox的兼容不太好">TinyMCE编辑器对FireFox的兼容不太好</a> (1)</li><li><a href="http://terence2008.info/archives/wordpress_database_optimize.html" title="WordPress数据库的一处性能优化">WordPress数据库的一处性能优化</a> (1)</li><li><a href="http://terence2008.info/archives/blog_maintenance.html" title="博客维护日记">博客维护日记</a> (0)</li><li><a href="http://terence2008.info/archives/change-space.html" title="换空间了">换空间了</a> (1)</li><li><a href="http://terence2008.info/archives/013.html" title="Google阅读器里RSS的显示问题">Google阅读器里RSS的显示问题</a> (0)</li><li><a href="http://terence2008.info/archives/010.html" title="网页中连续字符手动换行的方法">网页中连续字符手动换行的方法</a> (0)</li><li><a href="http://terence2008.info/archives/009.html" title="让flash植入代码符合xhtml标准">让flash植入代码符合xhtml标准</a> (1)</li><li><a href="http://terence2008.info/archives/001.html" title="写在最最开始">写在最最开始</a> (4)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/my-plugins.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</title>
		<link>http://terence2008.info/archives/talk-show.html</link>
		<comments>http://terence2008.info/archives/talk-show.html#comments</comments>
		<pubDate>Sat, 10 Apr 2010 16:54:52 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[视频]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=336</guid>
		<description><![CDATA[<p>      绿豆蛙，给生活加点料！（广告。。）话说中式英语能说到这个地步也就可以去混迹美国政坛了。到时候管你什么Chinglish还是British English还是American English，天下大统！</p>
<p>
<object type="application/x-shockwave-flash" width="480" height="400" data="http://player.youku.com/player.php/sid/XMTYyODQ0NDky/v.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://player.youku.com/player.php/sid/XMTYyODQ0NDky/v.swf" /></object></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀" href="http://terence2008.info/archives/talk-show.html">《留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/android-iphone-girl.html" title="智能手机的另一大功能——造星">智能手机的另一大功能——造星</a> (2)</li><li><a href="http://terence2008.info/archives/i-expect.html" title="我期待……">我期待……</a> (2)</li><li><a href="http://terence2008.info/archives/happy-mothers-day.html" title="母亲节——妈妈快乐！">母亲节——妈妈快乐！</a> (1)</li><li><a href="http://terence2008.info/archives/bird-dancing.html" title="鹦鹉版 杰克逊舞">鹦鹉版 杰克逊舞</a> (0)</li><li><a href="http://terence2008.info/archives/mario.html" title="没钱没车没房也想当英雄救公主？">没钱没车没房也想当英雄救公主？</a> (0)</li><li><a href="http://terence2008.info/archives/a-song.html" title="一首歌 两个人">一首歌 两个人</a> (0)</li><li><a href="http://terence2008.info/archives/014.html" title="天衣无缝的视频剪辑">天衣无缝的视频剪辑</a> (2)</li><li><a href="http://terence2008.info/archives/012.html" title="如果我是个男孩要带女朋友回家">如果我是个男孩要带女朋友回家</a> (0)</li><li><a href="http://terence2008.info/archives/011.html" title="朝鲜大妈，我被你吓到了= =！">朝鲜大妈，我被你吓到了= =！</a> (0)</li><li><a href="http://terence2008.info/archives/008.html" title="信春哥 死后四次原地满血复活">信春哥 死后四次原地满血复活</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/talk-show.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>八种排序算法效率比较</title>
		<link>http://terence2008.info/archives/sorting_compare.html</link>
		<comments>http://terence2008.info/archives/sorting_compare.html#comments</comments>
		<pubDate>Sat, 10 Apr 2010 06:51:37 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[开发技术]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[算法]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=302</guid>
		<description><![CDATA[<p>      从刚上大一那会儿学的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/c" title="查看 C 的全部文章">C</a></span>语言开始，就已经接触到了不少排序<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%ae%97%e6%b3%95" title="查看 算法 的全部文章">算法</a></span>，但当时都只是为了完成简单的排序任务而已，而且所给的数据也不够多，所以看不出各个排序<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%ae%97%e6%b3%95" title="查看 算法 的全部文章">算法</a></span>间的执行效率的优劣。最近有个数据结构课程设计的实验，是有关于排序<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%ae%97%e6%b3%95" title="查看 算法 的全部文章">算法</a></span>之间的效率比较，我就顺便把它放上来了，并对各个算法执行的效率时间做了柱形统计图表。此次实验主要测试了8种排序算法：插入排序、快速排序、冒泡排序、希尔排序、简单选择排序、堆排序、归并排序、折半插入排序。</p>
<p>      总共建立了三种情况，分别是平均排序、最好情况排序、最坏情况排序。第一种情况就是使用了VC6.0下的随机数生成函数输出100000个随机数进行排序；第二种情况是100000个数本身已经按从小到大的顺序排列了；第三种情况就是100000个数全部是按逆序排列。代码如下：</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include&lt;stdio.h&gt;</span>
<span style="color: #339933;">#include&lt;stdlib.h&gt;</span>
<span style="color: #339933;">#include&lt;time.h&gt;</span>
<span style="color: #339933;">#include&lt;windows.h&gt;</span>
<span style="color: #339933;">#define MAX 100000</span>
&nbsp;
<span style="color: #993333;">void</span> InsSort<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> r<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> length<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span>j<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span>length<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		r<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>r<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		j<span style="color: #339933;">=</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			r<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			j<span style="color: #339933;">=</span>j<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		r<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>r<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>       <span style="color: #666666; font-style: italic;">//插入排序</span>
&nbsp;
<span style="color: #993333;">void</span> swap<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> <span style="color: #339933;">&amp;</span>x<span style="color: #339933;">,</span><span style="color: #993333;">int</span> <span style="color: #339933;">&amp;</span>y<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> z<span style="color: #339933;">;</span>
	z<span style="color: #339933;">=</span>x<span style="color: #339933;">;</span>
	x<span style="color: #339933;">=</span>y<span style="color: #339933;">;</span>
	y<span style="color: #339933;">=</span>z<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">int</span> median3<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> left<span style="color: #339933;">,</span><span style="color: #993333;">int</span> right<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> center<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>left<span style="color: #339933;">+</span>right<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>left<span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span>a<span style="color: #009900;">&#91;</span>center<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
		swap<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>left<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>a<span style="color: #009900;">&#91;</span>center<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>left<span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span>a<span style="color: #009900;">&#91;</span>right<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
		swap<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>left<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>a<span style="color: #009900;">&#91;</span>right<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>center<span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span>a<span style="color: #009900;">&#91;</span>right<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
		swap<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>center<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>a<span style="color: #009900;">&#91;</span>right<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	swap<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>center<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>a<span style="color: #009900;">&#91;</span>right<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> a<span style="color: #009900;">&#91;</span>right<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> insertionsort<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> n<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> j<span style="color: #339933;">,</span>p<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> tmp<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>p<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>p<span style="color: #339933;">&lt;=</span>n<span style="color: #339933;">;</span>p<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		tmp<span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span>p<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span>p<span style="color: #339933;">;</span>j<span style="color: #339933;">&gt;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">&amp;&amp;</span>a<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span>tmp<span style="color: #339933;">;</span>j<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span>
			a<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		a<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>tmp<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> qsort<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> left<span style="color: #339933;">,</span><span style="color: #993333;">int</span> right<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span>j<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> pivot<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>left<span style="color: #339933;">+</span><span style="color: #0000dd;">2</span><span style="color: #339933;">&lt;=</span>right<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		pivot<span style="color: #339933;">=</span>median3<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>left<span style="color: #339933;">,</span>right<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		i<span style="color: #339933;">=</span>left<span style="color: #339933;">;</span>j<span style="color: #339933;">=</span>right<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">;;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span><span style="color: #339933;">++</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span>pivot<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span><span style="color: #339933;">--</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span>pivot<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">&lt;</span>j<span style="color: #009900;">&#41;</span>
				swap<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>a<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">else</span>
				<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		swap<span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>a<span style="color: #009900;">&#91;</span>right<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		qsort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>left<span style="color: #339933;">,</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		qsort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>right<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
		insertionsort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">+</span>left<span style="color: #339933;">,</span>right<span style="color: #339933;">-</span>left<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> quicksort<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> n<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	qsort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>n<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>      <span style="color: #666666; font-style: italic;">//快速排序</span>
&nbsp;
<span style="color: #993333;">void</span> BubbleSort<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> r<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> length<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span>j<span style="color: #339933;">,</span>temp<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span>length<span style="color: #339933;">;</span>j<span style="color: #339933;">&gt;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>j<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>j<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&gt;</span>r<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				temp<span style="color: #339933;">=</span>r<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				r<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>r<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				r<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>temp<span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>      <span style="color: #666666; font-style: italic;">//冒泡排序</span>
&nbsp;
<span style="color: #993333;">void</span> ShellInsert<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> r<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> length<span style="color: #339933;">,</span><span style="color: #993333;">int</span> delta<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span>j<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">+</span>delta<span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span>length<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span>r<span style="color: #009900;">&#91;</span>i<span style="color: #339933;">-</span>delta<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			r<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>r<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span>i<span style="color: #339933;">-</span>delta<span style="color: #339933;">;</span>j<span style="color: #339933;">&gt;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">&amp;&amp;</span>r<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>j<span style="color: #339933;">-=</span>delta<span style="color: #009900;">&#41;</span>
				r<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">+</span>delta<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			r<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">+</span>delta<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>r<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span>  ShellSort<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> r<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #993333;">int</span> length<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> delt<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #993333;">int</span> n<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span> 
	<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span>n<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;++</span>i<span style="color: #009900;">&#41;</span>
		ShellInsert<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">,</span>length<span style="color: #339933;">,</span>delt<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>       <span style="color: #666666; font-style: italic;">//希尔排序</span>
&nbsp;
<span style="color: #993333;">void</span> SelectSort<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> r<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> length<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span>j<span style="color: #339933;">,</span>k<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> n<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> x<span style="color: #339933;">;</span>
    n<span style="color: #339933;">=</span>length<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span>n<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;++</span>i<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		k<span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span>i<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>j<span style="color: #339933;">&lt;=</span>n<span style="color: #339933;">;++</span>j<span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span>r<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
				k<span style="color: #339933;">=</span>j<span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> k<span style="color: #339933;">!=</span>i<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				x<span style="color: #339933;">=</span> r<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				r<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>r<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
				r<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>x<span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>        <span style="color: #666666; font-style: italic;">//简单选择排序</span>
&nbsp;
<span style="color: #993333;">void</span> sift<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> r<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> k<span style="color: #339933;">,</span><span style="color: #993333;">int</span> m<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> t<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span>j<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> x<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> finished<span style="color: #339933;">;</span>
	t<span style="color: #339933;">=</span> r<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	x<span style="color: #339933;">=</span>r<span style="color: #009900;">&#91;</span>k<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	i<span style="color: #339933;">=</span>k<span style="color: #339933;">;</span>
	j<span style="color: #339933;">=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">*</span>i<span style="color: #339933;">;</span>
	finished<span style="color: #339933;">=</span>FALSE<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">&lt;=</span>m<span style="color: #339933;">&amp;&amp;!</span>finished<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>     
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">&lt;</span>m<span style="color: #339933;">&amp;&amp;</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span> r<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
			j<span style="color: #339933;">=</span>j<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">&gt;=</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
			finished<span style="color: #339933;">=</span>TRUE<span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span> 
		<span style="color: #009900;">&#123;</span>
			r<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>r<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			i<span style="color: #339933;">=</span>j<span style="color: #339933;">;</span>
			j<span style="color: #339933;">=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">*</span>i<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	r<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>t<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> crt_heap<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> r<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #993333;">int</span> length<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span>n<span style="color: #339933;">;</span>
    n<span style="color: #339933;">=</span>length<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span>n<span style="color: #339933;">/</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&gt;=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;--</span>i<span style="color: #009900;">&#41;</span> 
		sift<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">,</span>i<span style="color: #339933;">,</span>n<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> HeapSort<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> r<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> length<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span>n<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> b<span style="color: #339933;">;</span>
	crt_heap<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">,</span>length<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	n<span style="color: #339933;">=</span> length<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span>n<span style="color: #339933;">;</span>i<span style="color: #339933;">&gt;=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;--</span>i<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		b<span style="color: #339933;">=</span>r<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		r<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>r<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		r<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>b<span style="color: #339933;">;</span>
		sift<span style="color: #009900;">&#40;</span>r<span style="color: #339933;">,</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>       <span style="color: #666666; font-style: italic;">//堆排序</span>
&nbsp;
<span style="color: #993333;">void</span> merge<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> tmparray<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> lpos<span style="color: #339933;">,</span><span style="color: #993333;">int</span> rpos<span style="color: #339933;">,</span><span style="color: #993333;">int</span> rightend<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> i<span style="color: #339933;">,</span>leftend<span style="color: #339933;">,</span>numelements<span style="color: #339933;">,</span>tmppos<span style="color: #339933;">;</span>
	leftend<span style="color: #339933;">=</span>rpos<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	tmppos<span style="color: #339933;">=</span>lpos<span style="color: #339933;">;</span>
	numelements<span style="color: #339933;">=</span>rightend<span style="color: #339933;">-</span>lpos<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>lpos<span style="color: #339933;">&lt;=</span>leftend <span style="color: #339933;">&amp;&amp;</span> rpos<span style="color: #339933;">&lt;=</span>rightend<span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>a<span style="color: #009900;">&#91;</span>lpos<span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;=</span>a<span style="color: #009900;">&#91;</span>rpos<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
			tmparray<span style="color: #009900;">&#91;</span>tmppos<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span>lpos<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span>
			tmparray<span style="color: #009900;">&#91;</span>tmppos<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span>rpos<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>lpos<span style="color: #339933;">&lt;=</span>leftend<span style="color: #009900;">&#41;</span>
			tmparray<span style="color: #009900;">&#91;</span>tmppos<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span>lpos<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>rpos<span style="color: #339933;">&lt;=</span>rightend<span style="color: #009900;">&#41;</span>
			tmparray<span style="color: #009900;">&#91;</span>tmppos<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>a<span style="color: #009900;">&#91;</span>rpos<span style="color: #339933;">++</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>numelements<span style="color: #339933;">;</span>i<span style="color: #339933;">++,</span>rightend<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span>
			a<span style="color: #009900;">&#91;</span>rightend<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>tmparray<span style="color: #009900;">&#91;</span>rightend<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> msort<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> tmparray<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> left<span style="color: #339933;">,</span><span style="color: #993333;">int</span> right<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> center<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>left<span style="color: #339933;">&lt;</span>right<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		center<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>left<span style="color: #339933;">+</span>right<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
		msort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>tmparray<span style="color: #339933;">,</span>left<span style="color: #339933;">,</span>center<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		msort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>tmparray<span style="color: #339933;">,</span>center<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>right<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		merge<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>tmparray<span style="color: #339933;">,</span>left<span style="color: #339933;">,</span>center<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>right<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #993333;">void</span> mergesort<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> a<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> n<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> <span style="color: #339933;">*</span>tmparray<span style="color: #339933;">;</span>
	tmparray<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>malloc<span style="color: #009900;">&#40;</span>n<span style="color: #339933;">*</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>tmparray<span style="color: #339933;">!=</span>NULL<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		msort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>tmparray<span style="color: #339933;">,</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>n<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		free<span style="color: #009900;">&#40;</span>tmparray<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;no space for tmp array!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>        <span style="color: #666666; font-style: italic;">//归并排序</span>
&nbsp;
<span style="color: #993333;">void</span> BInsertSort<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> num<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #993333;">int</span> n<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> length<span style="color: #339933;">=</span>n<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> low<span style="color: #339933;">,</span>high<span style="color: #339933;">,</span>i<span style="color: #339933;">,</span>j<span style="color: #339933;">,</span>m<span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span>length<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	   num<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>num<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	   low<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	   high<span style="color: #339933;">=</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	   <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>low<span style="color: #339933;">&lt;=</span>high<span style="color: #009900;">&#41;</span>
	   <span style="color: #009900;">&#123;</span>
		   m<span style="color: #339933;">=</span><span style="color: #009900;">&#40;</span>low<span style="color: #339933;">+</span>high<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #0000dd;">2</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>num<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">&lt;</span>num<span style="color: #009900;">&#91;</span>m<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
				high<span style="color: #339933;">=</span>m<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">else</span>
				low<span style="color: #339933;">=</span>m<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>
	   <span style="color: #009900;">&#125;</span>
	   <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>j<span style="color: #339933;">=</span>i<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>j<span style="color: #339933;">&gt;=</span>high<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #339933;">;</span>j<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span>
		   num<span style="color: #009900;">&#91;</span>j<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>num<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	   num<span style="color: #009900;">&#91;</span>high<span style="color: #339933;">+</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>num<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>        <span style="color: #666666; font-style: italic;">//折半插入排序</span>
&nbsp;
<span style="color: #993333;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">long</span> dwStart<span style="color: #339933;">,</span>dwStop<span style="color: #339933;">,</span>runtime<span style="color: #339933;">;</span>
	<span style="color: #993333;">int</span> num<span style="color: #009900;">&#91;</span>MAX<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>a<span style="color: #009900;">&#91;</span>MAX<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>i<span style="color: #339933;">,</span>j<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	srand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #993333;">unsigned</span><span style="color: #009900;">&#41;</span>time<span style="color: #009900;">&#40;</span>NULL<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		num<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>rand<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;生成%d个随机数运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>MAX<span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;********平均排序时间********<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>num<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	InsSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用插入排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>num<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	quicksort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用快速排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>num<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	BubbleSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用冒泡排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #993333;">int</span> delt<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span><span style="color: #009900;">&#123;</span><span style="color: #0000dd;">100</span><span style="color: #339933;">,</span><span style="color: #0000dd;">80</span><span style="color: #339933;">,</span><span style="color: #0000dd;">60</span><span style="color: #339933;">,</span><span style="color: #0000dd;">40</span><span style="color: #339933;">,</span><span style="color: #0000dd;">20</span><span style="color: #339933;">,</span><span style="color: #0000dd;">10</span><span style="color: #339933;">,</span><span style="color: #0000dd;">5</span><span style="color: #339933;">,</span><span style="color: #0000dd;">3</span><span style="color: #339933;">,</span><span style="color: #0000dd;">2</span><span style="color: #339933;">,</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>num<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	ShellSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #339933;">,</span>delt<span style="color: #339933;">,</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用希尔排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>num<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SelectSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用简单选择排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>num<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	HeapSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用堆排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>num<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	mergesort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用归并排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>num<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	BInsertSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用折半插入排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;****************************<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;******最好情况排序时间******<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	InsSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用插入排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	quicksort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用快速排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	BubbleSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用冒泡排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	ShellSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #339933;">,</span>delt<span style="color: #339933;">,</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用希尔排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SelectSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用简单选择排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	HeapSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用堆排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	mergesort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用归并排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	BInsertSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用折半插入排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;****************************<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;******最坏情况排序时间******<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span>MAX<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>j<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>j<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">--,</span>j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	InsSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用插入排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span>MAX<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>j<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>j<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">--,</span>j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	quicksort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用快速排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span>MAX<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>j<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>j<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">--,</span>j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	BubbleSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用冒泡排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span>MAX<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>j<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>j<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">--,</span>j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	ShellSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #339933;">,</span>delt<span style="color: #339933;">,</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用希尔排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span>MAX<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>j<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>j<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">--,</span>j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	SelectSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用简单选择排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span>MAX<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>j<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>j<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">--,</span>j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	HeapSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用堆排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span>MAX<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>j<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>j<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">--,</span>j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	mergesort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用归并排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span>MAX<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span>j<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span>j<span style="color: #339933;">&lt;</span>MAX<span style="color: #339933;">;</span>i<span style="color: #339933;">--,</span>j<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		a<span style="color: #009900;">&#91;</span>j<span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span>i<span style="color: #339933;">;</span>
	dwStart<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	BInsertSort<span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span>MAX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	dwStop<span style="color: #339933;">=</span>GetTickCount<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	runtime<span style="color: #339933;">=</span>dwStop<span style="color: #339933;">-</span>dwStart<span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;使用折半插入排序运行了%ldms<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span>runtime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;****************************<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>排序测试完成！&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	getchar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>      执行程序是个很漫长的过程，像对于冒泡排序之类的算法，十万个数的排序再好的机器也得算上半天，不过像快速排序之类的算法如果不给予足够多的数据的话，执行时间永远是0毫秒。所以为了测算精确和公平比较，时间长我就慢慢熬吧。。。以下是我用执行完后的结果做成的统计图表（ps：图表中的数据是我在学院机器上的结果，在自己电脑上时间肯定会少许多，就懒得再算一遍了，反正情况都一样~~）：</p>
<p><a href="http://terence2008.info/wp-content/uploads/2010/04/sort1.jpg" rel="lightbox[302]" title="平均排序时间"><img class="alignnone size-medium wp-image-304" title="平均排序时间" src="http://terence2008.info/wp-content/uploads/2010/04/sort1-300x189.jpg" alt="" width="300" height="189" /></a></p>
<p><a href="http://terence2008.info/wp-content/uploads/2010/04/sort2.jpg" rel="lightbox[302]" title="最好情况排序时间比较"><img class="alignnone size-medium wp-image-305" title="最好情况排序时间比较" src="http://terence2008.info/wp-content/uploads/2010/04/sort2-300x189.jpg" alt="" width="300" height="189" /></a></p>
<p><a href="http://terence2008.info/wp-content/uploads/2010/04/sort3.jpg" rel="lightbox[302]" title="最坏情况排序时间比较"><img class="alignnone size-medium wp-image-303" title="最坏情况排序时间比较" src="http://terence2008.info/wp-content/uploads/2010/04/sort3-300x189.jpg" alt="" width="300" height="189" /></a></p>
<p>      结果很明显，快速排序、堆排序、归并排序这三种执行效率最快，不过话说回来，冒泡排序的代码真的是最好写的！看来算法高效代码复杂与算法低下代码简单是个很辩证的关系啊！ <img src='https://terence2008.info/wp-includes/images/smilies/icon_eek.gif' alt=':shock:' class='wp-smiley' />  </p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="八种排序算法效率比较" href="http://terence2008.info/archives/sorting_compare.html">《八种排序算法效率比较》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/finding_compare.html" title="六种查找算法效率比较">六种查找算法效率比较</a> (8)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/sorting_compare.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>水的故事</title>
		<link>http://terence2008.info/archives/water.html</link>
		<comments>http://terence2008.info/archives/water.html#comments</comments>
		<pubDate>Tue, 06 Apr 2010 09:10:21 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[水]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=277</guid>
		<description><![CDATA[<p>      不用多说什么，又是一个很有创意的视频，把<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e6%b0%b4" title="查看 水 的全部文章">水</a></span>的一生用简单而又活泼的动画描述了出来。强烈建议放入小学自然科学课程！</p>
<p>
<object type="application/x-shockwave-flash" width="480" height="400" data="http://player.youku.com/player.php/sid/XOTY0MzkxNg==/v.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://player.youku.com/player.php/sid/XOTY0MzkxNg==/v.swf" /></object></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="水的故事" href="http://terence2008.info/archives/water.html">《水的故事》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/013.html" title="Google阅读器里RSS的显示问题">Google阅读器里RSS的显示问题</a> (0)</li><li><a href="http://terence2008.info/archives/009.html" title="让flash植入代码符合xhtml标准">让flash植入代码符合xhtml标准</a> (1)</li><li><a href="http://terence2008.info/archives/006.html" title="电子杂志《物华特刊》发布！">电子杂志《物华特刊》发布！</a> (2)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/water.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>换空间了</title>
		<link>http://terence2008.info/archives/change-space.html</link>
		<comments>http://terence2008.info/archives/change-space.html#comments</comments>
		<pubDate>Wed, 31 Mar 2010 08:47:21 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[伪静态]]></category>
		<category><![CDATA[空间]]></category>
		<category><![CDATA[虚拟主机]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=260</guid>
		<description><![CDATA[<p>      为了<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%a9%ba%e9%97%b4" title="查看 空间 的全部文章">空间</a></span>的问题挣扎了好久，终于在猪哥（以前他免费提供<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%a9%ba%e9%97%b4" title="查看 空间 的全部文章">空间</a></span>给我）对我说他的那台服务器今后再也不归他管后，才下决心去买个收费空间，被逼的啊！！这让我想起一首恶搞歌《被逼的》，取自杰克逊的《Beat it》，扯远了。。。</p>
<p>      班上和我一样在玩wp博客的仁兄跟人家合租了一台国外的主机，虽然可以不用备案，而且还能SSH，但我总感觉不靠谱，说不定哪天因为河蟹问题而挂了。所以还是将目光投向国内，其实国内的主机商很乱，想当的乱！公司直接为了利益争夺，使出了利用漏洞频繁攻击服务器的下三烂的招数，导致那些安全措施做得不好的公司要么被挂马要么网速变得极其不稳定。但对于我这样的学生来说，动辄几百元一年的<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%99%9a%e6%8b%9f%e4%b8%bb%e6%9c%ba" title="查看 虚拟主机 的全部文章">虚拟主机</a></span>服务来说显得浪费，我只想找一家物美价廉的主，难啊！</p>
<p>      最后我找到了“稳网”，一个和我的学校同城的公司位于经济开发区内，本想这速度应该不错，而且代理商给我发来了几个测试地址感觉都还不错。可真我掏出100大洋买下1.5G空间加100M数据库的合租空间后发现我错了。速度慢不说，还经常打不开页面，甚至报500错误。话说这几天微软又爆出一个超级漏洞，还没补丁发布，据主机商内部人士说近几天经常受到这个漏洞的攻击。无语，真的没的救了。但愿等一切恢复平静后空间的速度能够上来吧，虽然我不报什么希望。那句话说得好啊“一份价钱一份货”。</p>
<p>      买了空间后做的一件有意义的事就是学习了url重写，也就是<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e4%bc%aa%e9%9d%99%e6%80%81" title="查看 伪静态 的全部文章">伪静态</a></span>技术。国内大部分的主机都是win2003系统，在IIS下架设PHP网站最大缺点就是会在url里面添加一个index.php，比如像"http://www.abc.com/index.php/2010/10/abc"之类的样子。收费空间支持url重写功能，就是在网站的根目录下添加一个httpd.ini文件，里面添加重写规则就行，地址就成了"http://www.abc.com/2010/10/abc"。找了很多的网页，最后选定了一个只有15行规则的代码，写得很有水平，不像其他人写的规则达到了几十行之巨，而且还要根据自己PHP网站的实际情况添加删除对应规则。而现在我只要在原有基础上稍作修改，只要添加那些不需要url重写的目录规则就行了。代码共享出来：</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>ISAPI_Rewrite<span style="">&#93;</span></span>
# Defend your computer from some worm attacks
RewriteRule .*<span style="">&#40;</span>?:global.asa|default\.ida|root\.exe|\.\.<span style="">&#41;</span>.* . <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>F,I,O<span style="">&#93;</span></span>
RepeatLimit <span style="">32</span>
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# Rules to ensure that normal content gets through
RewriteRule /files/<span style="">&#40;</span>.*<span style="">&#41;</span> /files/$<span style="">1</span> <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>L<span style="">&#93;</span></span>
RewriteRule /wap<span style="">&#40;</span>.*<span style="">&#41;</span> /wap$<span style="">1</span> <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>L<span style="">&#93;</span></span>
RewriteRule /book<span style="">&#40;</span>.*<span style="">&#41;</span> /book$<span style="">1</span> <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>L<span style="">&#93;</span></span>
RewriteRule /time.swf /time.swf <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>L<span style="">&#93;</span></span>
RewriteRule /sitemap.xml /sitemap.xml <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>L<span style="">&#93;</span></span>
RewriteRule /favicon.ico /favicon.ico <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>L<span style="">&#93;</span></span>
# For file-based wordpress content <span style="">&#40;</span>i.e. theme<span style="">&#41;</span>, admin, etc.
RewriteRule /wp-<span style="">&#40;</span>.*<span style="">&#41;</span> /wp-$<span style="">1</span> <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>L<span style="">&#93;</span></span>
# For normal wordpress content, via index.php
RewriteRule ^/$ /index.php <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>L<span style="">&#93;</span></span>
RewriteRule /<span style="">&#40;</span>.*<span style="">&#41;</span> /index.php/$<span style="">1</span> <span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>L<span style="">&#93;</span></span></pre></div></div>

<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="换空间了" href="http://terence2008.info/archives/change-space.html">《换空间了》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/001.html" title="写在最最开始">写在最最开始</a> (4)</li><li><a href="http://terence2008.info/archives/wordpress_database_optimize.html" title="WordPress数据库的一处性能优化">WordPress数据库的一处性能优化</a> (1)</li><li><a href="http://terence2008.info/archives/blog_maintenance.html" title="博客维护日记">博客维护日记</a> (0)</li><li><a href="http://terence2008.info/archives/ssl_cdn_choose.html" title="关于SSL证书与CDN加速的选择">关于SSL证书与CDN加速的选择</a> (0)</li><li><a href="http://terence2008.info/archives/tinymce-firefox.html" title="TinyMCE编辑器对FireFox的兼容不太好">TinyMCE编辑器对FireFox的兼容不太好</a> (1)</li><li><a href="http://terence2008.info/archives/my-plugins.html" title="我正在使用的插件列表">我正在使用的插件列表</a> (1)</li><li><a href="http://terence2008.info/archives/013.html" title="Google阅读器里RSS的显示问题">Google阅读器里RSS的显示问题</a> (0)</li><li><a href="http://terence2008.info/archives/010.html" title="网页中连续字符手动换行的方法">网页中连续字符手动换行的方法</a> (0)</li><li><a href="http://terence2008.info/archives/009.html" title="让flash植入代码符合xhtml标准">让flash植入代码符合xhtml标准</a> (1)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/change-space.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>天衣无缝的视频剪辑</title>
		<link>http://terence2008.info/archives/014.html</link>
		<comments>http://terence2008.info/archives/014.html#comments</comments>
		<pubDate>Mon, 15 Mar 2010 08:44:38 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[制作]]></category>
		<category><![CDATA[视频]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=256</guid>
		<description><![CDATA[<p>      转自<a href="http://blog.sina.com.cn/jiaoshouxiaoxing" target="_blank">蠢爸爸小星博客</a>，被震撼了，暂且不说<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%a7%86%e9%a2%91" title="查看 视频 的全部文章">视频</a></span>是不是剪辑出来的，但从<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e5%88%b6%e4%bd%9c" title="查看 制作 的全部文章">制作</a></span>人员数量来说就相当庞大，加上种种复杂的道具，可见此<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%a7%86%e9%a2%91" title="查看 视频 的全部文章">视频</a></span>投入的成本有多么的大。</p>
<p>      说到我们的国家的独立电影貌似还是个空白，总是会听到电影界所谓的资深人士说要拍部符合国情的电影有多么的困难，可要是国人们能像老外那样人人参与其中来，哪怕只是投入了小小的成本也能辐射出巨大的效应来，不是只有所谓的大导演才能拍得出精彩的电影。我总感觉每届奥斯卡获奖的导演里有挺多人之前根本是无人知晓的说。。</p>
<p>      好电影需要用心灵去拍摄。</p>
<p>
<object type="application/x-shockwave-flash" width="480" height="400" data="http://player.youku.com/player.php/sid/XMTU1NzE0NTIw/v.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://player.youku.com/player.php/sid/XMTU1NzE0NTIw/v.swf" /></object></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="天衣无缝的视频剪辑" href="http://terence2008.info/archives/014.html">《天衣无缝的视频剪辑》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/android-iphone-girl.html" title="智能手机的另一大功能——造星">智能手机的另一大功能——造星</a> (2)</li><li><a href="http://terence2008.info/archives/i-expect.html" title="我期待……">我期待……</a> (2)</li><li><a href="http://terence2008.info/archives/happy-mothers-day.html" title="母亲节——妈妈快乐！">母亲节——妈妈快乐！</a> (1)</li><li><a href="http://terence2008.info/archives/bird-dancing.html" title="鹦鹉版 杰克逊舞">鹦鹉版 杰克逊舞</a> (0)</li><li><a href="http://terence2008.info/archives/mario.html" title="没钱没车没房也想当英雄救公主？">没钱没车没房也想当英雄救公主？</a> (0)</li><li><a href="http://terence2008.info/archives/a-song.html" title="一首歌 两个人">一首歌 两个人</a> (0)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/012.html" title="如果我是个男孩要带女朋友回家">如果我是个男孩要带女朋友回家</a> (0)</li><li><a href="http://terence2008.info/archives/011.html" title="朝鲜大妈，我被你吓到了= =！">朝鲜大妈，我被你吓到了= =！</a> (0)</li><li><a href="http://terence2008.info/archives/008.html" title="信春哥 死后四次原地满血复活">信春哥 死后四次原地满血复活</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/014.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google阅读器里RSS的显示问题</title>
		<link>http://terence2008.info/archives/013.html</link>
		<comments>http://terence2008.info/archives/013.html#comments</comments>
		<pubDate>Tue, 09 Mar 2010 12:48:53 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[网络技术]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[网页]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=241</guid>
		<description><![CDATA[<p>      稍微整了下RSS的内容输出，突然很想看看自己的博客在<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/google" title="查看 Google 的全部文章">Google</a></span>阅读器里显示效果如何，毕竟很多博客的被关注形式是RSS，所以某种程度讲，就算搞个再漂亮的前台也是白搭 <img src='https://terence2008.info/wp-includes/images/smilies/icon_eek.gif' alt=':shock:' class='wp-smiley' />  ……</p>
<p>      这不看不知道，看了才发现我的视频怎么都显示不出来呢？这其中我折腾了好久，开始还以为在改RSS输出的时候哪里搞坏了。看了“河蟹娱乐”的rss输出和我自个儿的比较后，发现了一个很严重的事实啊= =！<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/google" title="查看 Google 的全部文章">Google</a></span>阅读器竟然只认&lt;embed&gt;标签里面的视频，对&lt;object&gt;里的视而不见，真太岂有此理了，亏我当初还兴致勃勃写了关于“让<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/flash" title="查看 flash 的全部文章">flash</a></span>植入代码符合xhtml标准”的文章 <img src='https://terence2008.info/wp-includes/images/smilies/icon_confused.gif' alt=':???:' class='wp-smiley' /> </p>
<p>      接着又试验了QQ邮箱里面的“阅读空间”，也是相同的问题，不过有几家专业做RSS抓取的网站倒可以把视频识别出来。另外，代码显示插件wp-syntax在不同RSS浏览器里显示的效果也不一样，有的会根据我的CSS样式自动换行，有的就不会。</p>
<p>      看来RSS也和HTML一样呀，说是支持加兼容，但实际结果却又是另外回事。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="Google阅读器里RSS的显示问题" href="http://terence2008.info/archives/013.html">《Google阅读器里RSS的显示问题》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/thesis.html" title="浅谈不同浏览器地址栏中编码的差异">浅谈不同浏览器地址栏中编码的差异</a> (2)</li><li><a href="http://terence2008.info/archives/google-adsense.html" title="巧用Google AdSense赚美元">巧用Google AdSense赚美元</a> (1)</li><li><a href="http://terence2008.info/archives/tinymce-firefox.html" title="TinyMCE编辑器对FireFox的兼容不太好">TinyMCE编辑器对FireFox的兼容不太好</a> (1)</li><li><a href="http://terence2008.info/archives/010.html" title="网页中连续字符手动换行的方法">网页中连续字符手动换行的方法</a> (0)</li><li><a href="http://terence2008.info/archives/009.html" title="让flash植入代码符合xhtml标准">让flash植入代码符合xhtml标准</a> (1)</li><li><a href="http://terence2008.info/archives/ajaxswing.html" title="AjaxSwing4.4.0授权码">AjaxSwing4.4.0授权码</a> (2)</li><li><a href="http://terence2008.info/archives/wordpress_database_optimize.html" title="WordPress数据库的一处性能优化">WordPress数据库的一处性能优化</a> (1)</li><li><a href="http://terence2008.info/archives/blog_maintenance.html" title="博客维护日记">博客维护日记</a> (0)</li><li><a href="http://terence2008.info/archives/my-plugins.html" title="我正在使用的插件列表">我正在使用的插件列表</a> (1)</li><li><a href="http://terence2008.info/archives/water.html" title="水的故事">水的故事</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/013.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如果我是个男孩要带女朋友回家</title>
		<link>http://terence2008.info/archives/012.html</link>
		<comments>http://terence2008.info/archives/012.html#comments</comments>
		<pubDate>Sun, 07 Mar 2010 10:39:02 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[视频]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=238</guid>
		<description><![CDATA[<p>
<object type="application/x-shockwave-flash" width="480" height="400" data="http://player.youku.com/player.php/sid/XMTU0OTYyMTQ0/v.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://player.youku.com/player.php/sid/XMTU0OTYyMTQ0/v.swf" /></object>
</p>
<p>      超级巨声毕业演唱会上骆湚明和潭杰希唱的这首歌，算是校园民谣吧，挺有感觉的，很清爽，推荐下~~</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="如果我是个男孩要带女朋友回家" href="http://terence2008.info/archives/012.html">《如果我是个男孩要带女朋友回家》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/android-iphone-girl.html" title="智能手机的另一大功能——造星">智能手机的另一大功能——造星</a> (2)</li><li><a href="http://terence2008.info/archives/i-expect.html" title="我期待……">我期待……</a> (2)</li><li><a href="http://terence2008.info/archives/happy-mothers-day.html" title="母亲节——妈妈快乐！">母亲节——妈妈快乐！</a> (1)</li><li><a href="http://terence2008.info/archives/bird-dancing.html" title="鹦鹉版 杰克逊舞">鹦鹉版 杰克逊舞</a> (0)</li><li><a href="http://terence2008.info/archives/mario.html" title="没钱没车没房也想当英雄救公主？">没钱没车没房也想当英雄救公主？</a> (0)</li><li><a href="http://terence2008.info/archives/a-song.html" title="一首歌 两个人">一首歌 两个人</a> (0)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/014.html" title="天衣无缝的视频剪辑">天衣无缝的视频剪辑</a> (2)</li><li><a href="http://terence2008.info/archives/011.html" title="朝鲜大妈，我被你吓到了= =！">朝鲜大妈，我被你吓到了= =！</a> (0)</li><li><a href="http://terence2008.info/archives/008.html" title="信春哥 死后四次原地满血复活">信春哥 死后四次原地满血复活</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/012.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>朝鲜大妈，我被你吓到了= =！</title>
		<link>http://terence2008.info/archives/011.html</link>
		<comments>http://terence2008.info/archives/011.html#comments</comments>
		<pubDate>Sat, 27 Feb 2010 09:23:02 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[视频]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=235</guid>
		<description><![CDATA[<p>      请直接拖到第三十秒，原来朝鲜电视台是这么播新闻的呀，太有气势了！ <img src='https://terence2008.info/wp-includes/images/smilies/icon_exclaim.gif' alt=':!:' class='wp-smiley' /> </p>
<p>
<object type="application/x-shockwave-flash" width="480" height="400" data="http://player.youku.com/player.php/sid/XMTU0NDQ3MDgw/v.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://player.youku.com/player.php/sid/XMTU0NDQ3MDgw/v.swf" /></object></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="朝鲜大妈，我被你吓到了= =！" href="http://terence2008.info/archives/011.html">《朝鲜大妈，我被你吓到了= =！》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/android-iphone-girl.html" title="智能手机的另一大功能——造星">智能手机的另一大功能——造星</a> (2)</li><li><a href="http://terence2008.info/archives/i-expect.html" title="我期待……">我期待……</a> (2)</li><li><a href="http://terence2008.info/archives/happy-mothers-day.html" title="母亲节——妈妈快乐！">母亲节——妈妈快乐！</a> (1)</li><li><a href="http://terence2008.info/archives/bird-dancing.html" title="鹦鹉版 杰克逊舞">鹦鹉版 杰克逊舞</a> (0)</li><li><a href="http://terence2008.info/archives/mario.html" title="没钱没车没房也想当英雄救公主？">没钱没车没房也想当英雄救公主？</a> (0)</li><li><a href="http://terence2008.info/archives/a-song.html" title="一首歌 两个人">一首歌 两个人</a> (0)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/014.html" title="天衣无缝的视频剪辑">天衣无缝的视频剪辑</a> (2)</li><li><a href="http://terence2008.info/archives/012.html" title="如果我是个男孩要带女朋友回家">如果我是个男孩要带女朋友回家</a> (0)</li><li><a href="http://terence2008.info/archives/008.html" title="信春哥 死后四次原地满血复活">信春哥 死后四次原地满血复活</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/011.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>网页中连续字符手动换行的方法</title>
		<link>http://terence2008.info/archives/010.html</link>
		<comments>http://terence2008.info/archives/010.html#comments</comments>
		<pubDate>Tue, 23 Feb 2010 08:30:00 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[网络技术]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[网页]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=208</guid>
		<description><![CDATA[<p>      刚刚在发文的时候发现一个问题，在输入一整串长的英文代码时，<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%bd%91%e9%a1%b5" title="查看 网页 的全部文章">网页</a></span>不会自动进行换行，造成了部分超出文字因为一行长度限制，无法显示出来，为此找了不少网站，找到了有个变通的方法，还是比较方便的，拿出来分享下。</p>
<p>      就是在html模式下找到需要截断的地方加上&amp;#8203;字符，这样在浏览器里就能手动换行了，方便吧。不过缺点是复制用其处理过的文本时有大量不可打印的字符，但在观看上没有影响。主要懒得再去装什么代码高亮插件了，先将就着用吧。。。</p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="网页中连续字符手动换行的方法" href="http://terence2008.info/archives/010.html">《网页中连续字符手动换行的方法》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/tinymce-firefox.html" title="TinyMCE编辑器对FireFox的兼容不太好">TinyMCE编辑器对FireFox的兼容不太好</a> (1)</li><li><a href="http://terence2008.info/archives/013.html" title="Google阅读器里RSS的显示问题">Google阅读器里RSS的显示问题</a> (0)</li><li><a href="http://terence2008.info/archives/ajaxswing.html" title="AjaxSwing4.4.0授权码">AjaxSwing4.4.0授权码</a> (2)</li><li><a href="http://terence2008.info/archives/wordpress_database_optimize.html" title="WordPress数据库的一处性能优化">WordPress数据库的一处性能优化</a> (1)</li><li><a href="http://terence2008.info/archives/blog_maintenance.html" title="博客维护日记">博客维护日记</a> (0)</li><li><a href="http://terence2008.info/archives/thesis.html" title="浅谈不同浏览器地址栏中编码的差异">浅谈不同浏览器地址栏中编码的差异</a> (2)</li><li><a href="http://terence2008.info/archives/google-adsense.html" title="巧用Google AdSense赚美元">巧用Google AdSense赚美元</a> (1)</li><li><a href="http://terence2008.info/archives/my-plugins.html" title="我正在使用的插件列表">我正在使用的插件列表</a> (1)</li><li><a href="http://terence2008.info/archives/change-space.html" title="换空间了">换空间了</a> (1)</li><li><a href="http://terence2008.info/archives/009.html" title="让flash植入代码符合xhtml标准">让flash植入代码符合xhtml标准</a> (1)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/010.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>让flash植入代码符合xhtml标准</title>
		<link>http://terence2008.info/archives/009.html</link>
		<comments>http://terence2008.info/archives/009.html#comments</comments>
		<pubDate>Tue, 23 Feb 2010 07:11:03 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[网络技术]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[W3C]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=179</guid>
		<description><![CDATA[<p>      博客中添加<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/flash" title="查看 flash 的全部文章">flash</a></span>视频已是非常普遍的事，但有没有注意到一个问题，各大视频网站所提供的视频html分享代码并不符合xhtml里任何一个版本的标准。以下是添加了视频后的网站用w3c标准组织提供的xhtml验证网站验证出来的结果：</p>
<p><a href="http://terence2008.info/wp-content/uploads/2010/02/xhtml1.jpg" rel="lightbox[179]" title="xhtml验证"><img class="alignnone size-medium wp-image-180" title="xhtml验证" src="http://terence2008.info/wp-content/uploads/2010/02/xhtml1-300x167.jpg" alt="" width="300" height="167" /></a><a href="http://terence2008.info/wp-content/uploads/2010/02/xhtml2.jpg" rel="lightbox[179]" title="xhtml验证出现的错误"><img class="alignnone size-medium wp-image-181" title="xhtml验证出现的错误" src="http://terence2008.info/wp-content/uploads/2010/02/xhtml2-300x156.jpg" alt="" width="300" height="156" /></a></p>
<p>      我们来看视频网站提供的分享代码：</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">object</span> <span style="color: #000066;">classid</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clsid:d27cdb6e-ae6d-11cf-96b8-444553540000&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000066;">codebase</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;src&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;vedio.swf&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;embed <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;vedio.swf&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span>embed&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">object</span>&gt;</span></pre></div></div>

<p>      代码应分成两个部分分析，即前面的&lt;object&gt;标签段和后面的&lt;embed&gt;标签段，2段内容提供的都是相同的功能，之所以这么写是因为视频网站要做到各个浏览器的显示兼容，IE浏览器使用的是&lt;object&gt;标签，而FireFox用的是&lt;embed&gt;标签。</p>
<p>      出现xhtml错误的原因其实很简单，&lt;embed&gt;语法并不在w3c制定的xhtml标准内，其原因有很多，但我认为最主要是因为这个标签是网景公司当年叱咤风云的Netscape浏览器所创设的，中间可能有版权问题、标准问题乃至后来的浏览器没落等一系列的影响所导致的。虽然此标签仍被多数浏览器所支持，但从维护标准的立场来说，标准统一必是一个大的趋势。</p>
<p>      现在我们所要做的就是修改代码来做到符合标准，既然&lt;object&gt;标签是符合xhtml规范的，那么我们就从他入手。先删除&lt;embed&gt;标签段，但此时的&lt;object&gt;标签段只能在IE中发挥作用，而FireFox等第三方浏览器是显示不出视频的，原因是其中的：</p>
<blockquote><p>classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"</p>
</blockquote>
<p>      很明显，他是在调用<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/flash" title="查看 flash 的全部文章">flash</a></span>的com组件，非microsoft平台肯定不支持，取而代之的应是type属性，来指定object的数据类型。另外，FireFox用data属性来定位flash文件，而IE用param段来定位文件。有了这个思路接下来的事就好办了，我们只要加上以下两段来替换掉classid段：</p>
<blockquote><p>type="application/x-shockwave-flash"</p>
<p>data="xxx" //这边的xxx就是param段中value所包含的部分</p>
</blockquote>
<p>      整理后的代码如下：</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">object</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span> <span style="color: #000066;">data</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;vedio.swf&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;300&quot;</span> <span style="color: #000066;">codebase</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;src&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;vedio.swf&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">object</span>&gt;</span></pre></div></div>

<p>      可能会问，为什么还要保留codebase段，原因是保留他的话如果在碰到IE没有安装flash插件的情况，IE会自动下载插件并提示安装，反之就只会显示一个红叉。</p>
<p>      至此，代码就可以完美通过xhtml验证了，算是为了维护网页标准做出的小小的贡献吧~~ <img src='https://terence2008.info/wp-includes/images/smilies/icon_lol.gif' alt=':lol:' class='wp-smiley' />  </p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="让flash植入代码符合xhtml标准" href="http://terence2008.info/archives/009.html">《让flash植入代码符合xhtml标准》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/013.html" title="Google阅读器里RSS的显示问题">Google阅读器里RSS的显示问题</a> (0)</li><li><a href="http://terence2008.info/archives/001.html" title="写在最最开始">写在最最开始</a> (4)</li><li><a href="http://terence2008.info/archives/wordpress_database_optimize.html" title="WordPress数据库的一处性能优化">WordPress数据库的一处性能优化</a> (1)</li><li><a href="http://terence2008.info/archives/blog_maintenance.html" title="博客维护日记">博客维护日记</a> (0)</li><li><a href="http://terence2008.info/archives/tinymce-firefox.html" title="TinyMCE编辑器对FireFox的兼容不太好">TinyMCE编辑器对FireFox的兼容不太好</a> (1)</li><li><a href="http://terence2008.info/archives/my-plugins.html" title="我正在使用的插件列表">我正在使用的插件列表</a> (1)</li><li><a href="http://terence2008.info/archives/water.html" title="水的故事">水的故事</a> (0)</li><li><a href="http://terence2008.info/archives/change-space.html" title="换空间了">换空间了</a> (1)</li><li><a href="http://terence2008.info/archives/010.html" title="网页中连续字符手动换行的方法">网页中连续字符手动换行的方法</a> (0)</li><li><a href="http://terence2008.info/archives/006.html" title="电子杂志《物华特刊》发布！">电子杂志《物华特刊》发布！</a> (2)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/009.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>信春哥 死后四次原地满血复活</title>
		<link>http://terence2008.info/archives/008.html</link>
		<comments>http://terence2008.info/archives/008.html#comments</comments>
		<pubDate>Thu, 11 Feb 2010 14:39:21 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[视频]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=109</guid>
		<description><![CDATA[<p>      神人啊~~~话说昨天在同学聚会的时候听他们谈起<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%a7%86%e9%a2%91" title="查看 视频 的全部文章">视频</a></span>“PS”的问题，还真有那种软件可以做到，名字叫啥没记起来。不知做出来的效果如何，不过这哥们可不是吹的。。。</p>
<p>
<object type="application/x-shockwave-flash" width="480" height="400" data="http://player.youku.com/player.php/sid/XMTAxNTg0OTQw/v.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://player.youku.com/player.php/sid/XMTAxNTg0OTQw/v.swf" /></object></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="信春哥 死后四次原地满血复活" href="http://terence2008.info/archives/008.html">《信春哥 死后四次原地满血复活》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/android-iphone-girl.html" title="智能手机的另一大功能——造星">智能手机的另一大功能——造星</a> (2)</li><li><a href="http://terence2008.info/archives/i-expect.html" title="我期待……">我期待……</a> (2)</li><li><a href="http://terence2008.info/archives/happy-mothers-day.html" title="母亲节——妈妈快乐！">母亲节——妈妈快乐！</a> (1)</li><li><a href="http://terence2008.info/archives/bird-dancing.html" title="鹦鹉版 杰克逊舞">鹦鹉版 杰克逊舞</a> (0)</li><li><a href="http://terence2008.info/archives/mario.html" title="没钱没车没房也想当英雄救公主？">没钱没车没房也想当英雄救公主？</a> (0)</li><li><a href="http://terence2008.info/archives/a-song.html" title="一首歌 两个人">一首歌 两个人</a> (0)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/014.html" title="天衣无缝的视频剪辑">天衣无缝的视频剪辑</a> (2)</li><li><a href="http://terence2008.info/archives/012.html" title="如果我是个男孩要带女朋友回家">如果我是个男孩要带女朋友回家</a> (0)</li><li><a href="http://terence2008.info/archives/011.html" title="朝鲜大妈，我被你吓到了= =！">朝鲜大妈，我被你吓到了= =！</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/008.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>电子杂志《物华特刊》发布！</title>
		<link>http://terence2008.info/archives/006.html</link>
		<comments>http://terence2008.info/archives/006.html#comments</comments>
		<pubDate>Tue, 09 Feb 2010 09:06:25 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[电子刊]]></category>
		<category><![CDATA[网络]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=74</guid>
		<description><![CDATA[<p>      说到做电子杂志，我可是有了很多的经验，从zinemaker到现在的iebook，都有了不少接触，记得第一次做<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%94%b5%e5%ad%90%e5%88%8a" title="查看 电子刊 的全部文章">电子刊</a></span>还是大一的时候进学院的记者团那会儿，想做个实验性的改革，从以前单一的纸质报刊发展为<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e7%94%b5%e5%ad%90%e5%88%8a" title="查看 电子刊 的全部文章">电子刊</a></span>和传统报刊相结合的方式，可终究因为这样那样的问题没能坚持下来。</p>
<p>      这学期经过近一个月的努力，和记者团的成员一起完成了学院系列活动的总结——《物华特刊》的制作，界面很华丽，效果很明显，而且还是纯<span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/flash" title="查看 flash 的全部文章">flash</a></span>网站哦。总算之前的所有辛苦没有白费~~我暂时把它放在了我的网站空间里，做了个二级链接<a href="http://terence.org.ru/book" target="_blank">http://terence.org.ru/book</a>(需要浏览器全屏浏览)，欢迎围观指责！</p>
<p>      可发现把这个东西搬到学校服务器上是一个挺麻烦的事情，学院里没有老师管理现在服务器，导致ftp后台管理帐号得从校方的电教中心申请。看来等寒假一过我还是有的忙的。不过也没办法，总得有一个人来做个创新尝试吧，我承认我是个喜爱折腾的人。 <img src='https://terence2008.info/wp-includes/images/smilies/icon_rolleyes.gif' alt=':roll:' class='wp-smiley' />  </p>
<p>      先来几张截图吧：</p>
<p><a href="http://terence2008.info/wp-content/uploads/2010/02/book1.jpg" rel="lightbox[74]" title="book1"><img class="alignnone size-thumbnail wp-image-93" title="book1" src="http://terence2008.info/wp-content/uploads/2010/02/book1.jpg" alt="" width="150" height="110" /></a>   <a href="http://terence2008.info/wp-content/uploads/2010/02/book2.jpg" rel="lightbox[74]" title="book2"><img class="alignnone size-thumbnail wp-image-94" title="book2" src="http://terence2008.info/wp-content/uploads/2010/02/book2.jpg" alt="" width="150" height="110" /></a>   <a href="http://terence2008.info/wp-content/uploads/2010/02/book3.jpg" rel="lightbox[74]" title="book3"><img class="alignnone size-thumbnail wp-image-102" title="book3" src="http://terence2008.info/wp-content/uploads/2010/02/book3.jpg" alt="" width="150" height="110" /></a></p>
<blockquote><div> 　&raquo; 转载请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="电子杂志《物华特刊》发布！" href="http://terence2008.info/archives/006.html">《电子杂志《物华特刊》发布！》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/thesis.html" title="浅谈不同浏览器地址栏中编码的差异">浅谈不同浏览器地址栏中编码的差异</a> (2)</li><li><a href="http://terence2008.info/archives/water.html" title="水的故事">水的故事</a> (0)</li><li><a href="http://terence2008.info/archives/013.html" title="Google阅读器里RSS的显示问题">Google阅读器里RSS的显示问题</a> (0)</li><li><a href="http://terence2008.info/archives/009.html" title="让flash植入代码符合xhtml标准">让flash植入代码符合xhtml标准</a> (1)</li><li><a href="http://terence2008.info/archives/005.html" title="猜想2010年后的中国网络">猜想2010年后的中国网络</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/006.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>李献计历险记</title>
		<link>http://terence2008.info/archives/007.html</link>
		<comments>http://terence2008.info/archives/007.html#comments</comments>
		<pubDate>Sun, 07 Feb 2010 02:51:17 +0000</pubDate>
		<dc:creator>Terence</dc:creator>
				<category><![CDATA[随便写写]]></category>
		<category><![CDATA[视频]]></category>
		<category><![CDATA[转载]]></category>

		<guid isPermaLink="false">http://terence2008.info/?p=81</guid>
		<description><![CDATA[<p>
<object type="application/x-shockwave-flash" width="480" height="400" data="http://player.youku.com/player.php/sid/XMTM5MTg1NDY0/v.swf" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="wmode" value="transparent" /><param name="src" value="http://player.youku.com/player.php/sid/XMTM5MTg1NDY0/v.swf" /></object>
</p>
<p>　　《飞屋历险记》讲的是一个老人在弥留之际的想象。那么《李献计历险记》讲的则是一个失恋的年轻人的想象。 而这两个动画片就是我所看到的最好的片子。它们有着相同的内涵。只是主人公有所不同。一个是一个孤独无依的老人，一个是陷入失恋的情绪而不能自拔的青年。都叫做历险记，但实际上，这两个片子讲的都是幻觉——当一个人陷入某种无法自拔的情绪时所产生的幻觉。 <br />
　　在《李献计历险记》中关于李献计弄到50万人民币的片断里，总统的女儿问李献计：“你做这一切，都是为了一个女孩？”李献计说了一句在我看来最为深刻并且最为哀伤的话，他说：“其实就是为了自己，能从分手后的世界顺利逃走。” <br />
　　为了这个近乎不可能的目标，李献计开始了他的历险——一遍又一遍的把那款永远都打不穿的游戏给打穿。因为，据说打穿这个游戏之后，李献计就能够回到过去。一次又一次。李献计的头发胡子变长，又变短。像影片《阿甘正传》里那一段经典的揭示时间汹涌流逝的镜头一样，这部短片在这里也以一种让人措手不及，目瞪口呆的方式揭示了快速流走的时间是多么的不堪一击。所不同的是，阿甘在结束奔跑的时候，前面有象征着永恒希望的大海蓝天晚霞。而李献计在终于穿过那扇正确的门的时候，迎接他的，却是一个象征着永恒绝望的由雨后深渊所映照出来的自己。 <br />
　　短片开始结束。前面是李献计一直寻找的女孩，可是他再也迈不出半步。距离，在不知不觉中，变得好像时间流逝一样遥远；又好像梦境与现实一样可望不可及。——这就是这部短片的最后一幕：彻底的哀伤，彻底的平静。</p>
<blockquote><div> 　&raquo; <span class='wp_keywordlink_affiliate'><a href="http://terence2008.info/archives/tag/%e8%bd%ac%e8%bd%bd" title="查看 转载 的全部文章">转载</a></span>请注明来源：<a title="Terence的窝" href="http://terence2008.info">Terence的窝</a> &raquo; <a rel="bookmark" title="李献计历险记" href="http://terence2008.info/archives/007.html">《李献计历险记》</a></div></blockquote><h3  class="related_post_title">相关日志</h3><ul class="related_post"><li><a href="http://terence2008.info/archives/mario.html" title="没钱没车没房也想当英雄救公主？">没钱没车没房也想当英雄救公主？</a> (0)</li><li><a href="http://terence2008.info/archives/android-iphone-girl.html" title="智能手机的另一大功能——造星">智能手机的另一大功能——造星</a> (2)</li><li><a href="http://terence2008.info/archives/i-expect.html" title="我期待……">我期待……</a> (2)</li><li><a href="http://terence2008.info/archives/happy-mothers-day.html" title="母亲节——妈妈快乐！">母亲节——妈妈快乐！</a> (1)</li><li><a href="http://terence2008.info/archives/bird-dancing.html" title="鹦鹉版 杰克逊舞">鹦鹉版 杰克逊舞</a> (0)</li><li><a href="http://terence2008.info/archives/a-song.html" title="一首歌 两个人">一首歌 两个人</a> (0)</li><li><a href="http://terence2008.info/archives/talk-show.html" title="留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀">留学生王西Joe Wong用中国口音极重的英语 征服在场嘉宾 2010年美国记者年会脱口秀</a> (0)</li><li><a href="http://terence2008.info/archives/014.html" title="天衣无缝的视频剪辑">天衣无缝的视频剪辑</a> (2)</li><li><a href="http://terence2008.info/archives/012.html" title="如果我是个男孩要带女朋友回家">如果我是个男孩要带女朋友回家</a> (0)</li><li><a href="http://terence2008.info/archives/011.html" title="朝鲜大妈，我被你吓到了= =！">朝鲜大妈，我被你吓到了= =！</a> (0)</li></ul>]]></description>
			<wfw:commentRss>http://terence2008.info/archives/007.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.355 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2026-03-22 11:04:02 -->
<!-- Compression = gzip -->