<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title></title>
    <description>自己动手,丰衣足食!</description>
    <link>https://ljw718.github.io//</link>
    <atom:link href="https://ljw718.github.io//feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Sun, 30 Mar 2025 12:32:01 +0000</pubDate>
    <lastBuildDate>Sun, 30 Mar 2025 12:32:01 +0000</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
      <item>
        <title>Powershell完美支持Git</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#1安装posh-git&quot; id=&quot;markdown-toc-1安装posh-git&quot;&gt;1、安装posh-git&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2安装oh-my-posh需要科学上网&quot; id=&quot;markdown-toc-2安装oh-my-posh需要科学上网&quot;&gt;2、安装oh-my-posh（需要科学上网）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3安装文件图标库&quot; id=&quot;markdown-toc-3安装文件图标库&quot;&gt;3、安装文件图标库&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#4安装meslo字体推荐&quot; id=&quot;markdown-toc-4安装meslo字体推荐&quot;&gt;4、安装Meslo字体(推荐)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#5安装psreadline&quot; id=&quot;markdown-toc-5安装psreadline&quot;&gt;5、安装PSReadLine&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#6创建userprofileps1&quot; id=&quot;markdown-toc-6创建userprofileps1&quot;&gt;6、创建userProfile.ps1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#7最终效果图如下&quot; id=&quot;markdown-toc-7最终效果图如下&quot;&gt;7、最终效果图如下&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;1安装posh-git&quot;&gt;1、安装posh-git&lt;/h1&gt;
&lt;blockquote&gt;
  &lt;p&gt;Install-Module posh-git -Scope CurrentUser -Force&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;要在你的提示符中包含 Git 信息，那么需要导入 posh-git 模块。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Import-Module posh-git&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;要让 PowerShell 在每次启动时都导入 posh-git，请执行 Add-PoshGitToProfile 命令，它会在你的 $profile 脚本中添加导入语句。 此脚本会在每次打开新的 PowerShell 终端时执行。 注意，存在多个 $profile 脚本。 例如，其中一个是控制台的，另一个则属于 ISE。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Add-PoshGitToProfile -AllHosts&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;2安装oh-my-posh需要科学上网&quot;&gt;2、安装oh-my-posh（需要科学上网）&lt;/h1&gt;
&lt;blockquote&gt;
  &lt;p&gt;winget install JanDeDobbeleer.OhMyPosh -s winget&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;3安装文件图标库&quot;&gt;3、安装文件图标库&lt;/h1&gt;
&lt;blockquote&gt;
  &lt;p&gt;Install-Module -Name Terminal-Icons -Repository PSGallery&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;PS：文件图标库能否正常使用，必须依赖于Nerd Fonts字体。&lt;/p&gt;

&lt;p&gt;使用文件图标库，需要在PowerShell配置文件中，增加如下命令：&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Import-Module -Name Terminal-Icons&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;4安装meslo字体推荐&quot;&gt;4、安装Meslo字体(推荐)&lt;/h1&gt;
&lt;p&gt;推荐使用MesloLGM NF字体，&lt;a href=&quot;https://github.com/ryanoasis/nerd-fonts/releases/download/v2.3.3/Meslo.zip&quot;&gt;点此即可直接下载Meslo字体(v2.3.3)&lt;/a&gt;。
下载完成后解压，全选右键点击安装即可自动安装。&lt;/p&gt;

&lt;h1 id=&quot;5安装psreadline&quot;&gt;5、安装PSReadLine&lt;/h1&gt;
&lt;p&gt;Install-Module -Name PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck&lt;/p&gt;

&lt;h1 id=&quot;6创建userprofileps1&quot;&gt;6、创建userProfile.ps1&lt;/h1&gt;
&lt;p&gt;Powershell窗口输入命令：notepad.exe $PROFILE
复制以下文本到xxx_Profile.ps1文件&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# set PowerShell to UTF-8
[console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding

#Import-Module posh-git
#Import-Module oh-my-posh
#Set-PoshPrompt Paradox
$omp_config = Join-Path $PSScriptRoot &quot;.\takuya.omp.json&quot;
oh-my-posh --init --shell pwsh --config $omp_config | Invoke-Expression

Import-Module -Name Terminal-Icons

# PSReadLine
Set-PSReadLineOption -EditMode Emacs
Set-PSReadLineOption -BellStyle None
Set-PSReadLineKeyHandler -Chord &apos;Ctrl+d&apos; -Function DeleteChar
Set-PSReadLineOption -PredictionSource History
# 启用自动补全的快捷键（例如，在输入命令时按Tab键）
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete

# Fzf
# Import-Module PSFzf -Cmdlet fzf
# Set-PsFzfOption -PSReadlineChordReverseHistory &apos;Ctrl+r&apos;

# Env
#$env:GIT_SSH = &quot;C:\Windows\system32\OpenSSH\ssh.exe&quot;

# Alias
Set-Alias -Name vim -Value nvim
Set-Alias ll ls
# Set-Alias g git
# Set-Alias grep findstr
# Set-Alias tig &apos;C:\Program Files\Git\usr\bin\tig.exe&apos;
# Set-Alias less &apos;C:\Program Files\Git\usr\bin\less.exe&apos;

# Utilities
function which ($command) {
  Get-Command -Name $command -ErrorAction SilentlyContinue |
    Select-Object -ExpandProperty Path -ErrorAction SilentlyContinue
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;7最终效果图如下&quot;&gt;7、最终效果图如下&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;/styles/images/Git/powershell.png&quot; alt=&quot;powershell&quot; /&gt;&lt;/p&gt;

&lt;p&gt;参考：
https://blog.csdn.net/weixin_44155966/article/details/142624257&lt;/p&gt;

&lt;p&gt;https://blog.csdn.net/ZHOU_YONG915/article/details/129733931&lt;/p&gt;

</description>
        <pubDate>Sun, 30 Mar 2025 04:08:00 +0000</pubDate>
        <link>https://ljw718.github.io//2025/03/30/PowershellSupportGit/</link>
        <guid isPermaLink="true">https://ljw718.github.io//2025/03/30/PowershellSupportGit/</guid>
        
        
        <category>Git</category>
        
      </item>
    
      <item>
        <title>How To Use Uthash</title>
        <description>&lt;h1 id=&quot;uthash简介&quot;&gt;uthash简介&lt;/h1&gt;

&lt;p&gt;  由于C语言本身不存在哈希，但是当需要使用哈希表的时候自己构建哈希会异常复杂。因此，我们可以调用开源的第三方头文件，&lt;strong&gt;这只是一个头文件&lt;/strong&gt;：uthash.h。我们需要做的就是将头文件复制到您的项目中，然后：#include “uthash.h”。由于uthash仅是头文件，因此没有可链接的库代码。&lt;/p&gt;

&lt;p&gt;  使用uthash添加，查找和删除通常是常数时间的操作，此哈希的目标是简约高效。它大约有1000行C。它会自动内联，因为它是作为宏实现的。
  uthash还包括三个额外的头文件，主要提供链表，动态数组和字符串。utlist.h为C结构提供了链接列表宏。utarray.h使用宏实现动态数组。utstring.h实现基本的动态字符串。&lt;/p&gt;

&lt;h1 id=&quot;uthash的使用&quot;&gt;uthash的使用&lt;/h1&gt;

&lt;h2 id=&quot;定义结构体&quot;&gt;定义结构体&lt;/h2&gt;

&lt;p&gt;  这里我们将id作为一个索引值，也就是键值，将name作为value。&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&quot;uthash.h&quot;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;                    &lt;span class=&quot;cm&quot;&gt;/* key */&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;UT_hash_handle&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;         &lt;span class=&quot;cm&quot;&gt;/* makes this structure hashable */&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;cm&quot;&gt;/*声明哈希为NULL指针*/&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;    &lt;span class=&quot;cm&quot;&gt;/* important! initialize to NULL */&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;  注意：一定要包含UT_hash_handle hh;hh不需要初始化。它可以命名为任何名称，但是我们一般都命名为hh。&lt;/p&gt;

&lt;h2 id=&quot;添加&quot;&gt;添加&lt;/h2&gt;

&lt;p&gt;  HASH_ADD_INT表示添加的键值为int类型
  HASH_ADD_STR表示添加的键值为字符串类型
  HASH_ADD_PTR表示添加的键值为指针类型
  HASH_ADD表示添加的键值可以是任意类型&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;add_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;cm&quot;&gt;/*重复性检查，当把两个相同key值的结构体添加到哈希表中时会报错*/&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HASH_FIND_INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;cm&quot;&gt;/* id already in the hash? */&lt;/span&gt;
    &lt;span class=&quot;cm&quot;&gt;/*只有在哈希中不存在ID的情况下，我们才创建该项目并将其添加。否则，我们只修改已经存在的结构。*/&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;HASH_ADD_INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;cm&quot;&gt;/* id: name of key field */&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;strcpy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;  HASH_ADD_INT函数中，第一个参数users是哈希表，第二个参数id是键字段的名称。最后一个参数s是指向要添加的结构的指针。&lt;/p&gt;

&lt;h2 id=&quot;查找&quot;&gt;查找&lt;/h2&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;find_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HASH_FIND_INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;cm&quot;&gt;/* s: output pointer */&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;  在上述代码中，第一个参数users是哈希表，&lt;strong&gt;第二个参数是user_id的地址&lt;/strong&gt;（&lt;strong&gt;一定要传递地址&lt;/strong&gt;）。最后s是输出变量。当可以在哈希表中找到相应键值时，s返回给定键的结构，当找不到时s返回NULL。&lt;/p&gt;

&lt;h2 id=&quot;替换&quot;&gt;替换&lt;/h2&gt;

&lt;p&gt;  HASH_REPLACE宏等效于HASH_ADD宏，HASH_REPLACE会尝试查找和删除项目外。如果找到并删除了一个项目，它还将返回该项目的指针作为输出参数。&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;replace_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HashHead&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HashNode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newNode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HashNode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oldNode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;find_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newNode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;oldNode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;HASH_REPLACE_INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newNode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldNode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;删除&quot;&gt;删除&lt;/h2&gt;

&lt;p&gt;  要从哈希表中删除结构，必须具有指向它的指针。（如果只有键，请先执行HASH_FIND以获取结构指针）。&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;delete_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HASH_DEL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;cm&quot;&gt;/* user: pointer to deletee */&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;free&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;             &lt;span class=&quot;cm&quot;&gt;/* optional; it&apos;s up to you! */&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;  同样，这里users是哈希表，user是指向我们要从哈希中删除的结构的指针。&lt;/p&gt;

&lt;p&gt;  删除结构只是将其从哈希表中删除，并非free 。何时释放结构的选择完全取决于自己；uthash永远不会释放您的结构&lt;/p&gt;

&lt;h2 id=&quot;循环删除&quot;&gt;循环删除&lt;/h2&gt;

&lt;p&gt;  HASH_ITER是一个宏定义，程序执行时被替换为一个循环。&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;delete_all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;HASH_ITER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HASH_DEL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;cm&quot;&gt;/* delete; users advances to next */&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;free&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;            &lt;span class=&quot;cm&quot;&gt;/* optional- if you want to free  */&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;删除哈希表所有元素&quot;&gt;删除哈希表所有元素&lt;/h2&gt;

&lt;p&gt;  如果您只想删除所有项目，但不释放它们或进行每个元素的清理，则可以通过一次操作更有效地做到这一点：&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;HASH_CLEAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;  之后，列表头（此处为users）将设置为NULL。&lt;/p&gt;

&lt;h2 id=&quot;计算哈希表元素个数&quot;&gt;计算哈希表元素个数&lt;/h2&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num_users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;num_users&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HASH_COUNT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;there are %u users&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num_users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;  当users为NULL时，HASH_COUNT会返回0.&lt;/p&gt;

&lt;h2 id=&quot;遍历哈希表中的所有项目&quot;&gt;遍历哈希表中的所有项目&lt;/h2&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;print_users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;user id %d: name %s&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;  还有一个hh.prev指针，可用于从任何已知项开始向后迭代哈希。
  由于hh.prev和hh.next字段的缘故，可以在哈希中向前和向后迭代。可以通过重复跟随这些指针来访问哈希中的所有项目，因此哈希也是&lt;strong&gt;双链表&lt;/strong&gt;。&lt;/p&gt;

&lt;h2 id=&quot;排序哈希表&quot;&gt;排序哈希表&lt;/h2&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;HASH_SORT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name_sort&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;  第二个参数是指向比较函数的指针。它必须接受两个指针参数（要比较的项目），并且如果第一个项目分别在第二个项目之前，等于或之后排序，则必须返回小于零，零或大于零的int。 （这与标准C库中的strcmp或qsort使用的约定相同）。&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sort_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;cm&quot;&gt;/* compare a to b (cast a and b appropriately)
   * return (int) -1 if (a &amp;lt; b)
   * return (int)  0 if (a == b)
   * return (int)  1 if (a &amp;gt; b)
   */&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;  name_sort和id_sort的两个排序函数示例。&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;name_sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strcmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;id_sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sort_by_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HASH_SORT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name_sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sort_by_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HASH_SORT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id_sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;完整代码&quot;&gt;完整代码&lt;/h2&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;   /* gets */&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;  /* atoi, malloc */&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;  /* strcpy */&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&quot;uthash.h&quot;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;                    &lt;span class=&quot;cm&quot;&gt;/* key */&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;UT_hash_handle&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;         &lt;span class=&quot;cm&quot;&gt;/* makes this structure hashable */&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;add_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;HASH_FIND_INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;cm&quot;&gt;/* id already in the hash? */&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;HASH_ADD_INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;cm&quot;&gt;/* id: name of key field */&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;strcpy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;find_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;HASH_FIND_INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;cm&quot;&gt;/* s: output pointer */&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;delete_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HASH_DEL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;cm&quot;&gt;/* user: pointer to deletee */&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;free&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;delete_all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;HASH_ITER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HASH_DEL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;  &lt;span class=&quot;cm&quot;&gt;/* delete it (users advances to next) */&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;free&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;current_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;             &lt;span class=&quot;cm&quot;&gt;/* free it */&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;print_users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;user id %d: name %s&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;name_sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strcmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;id_sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sort_by_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HASH_SORT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name_sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;sort_by_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HASH_SORT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id_sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;running&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num_users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;running&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; 1. add user&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; 2. add/rename user by id&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; 3. find user&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; 4. delete user&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; 5. delete all users&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; 6. sort items by name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; 7. sort items by id&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; 8. print users&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; 9. count users&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;10. quit&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;gets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;atoi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;name?&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;add_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;id?&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;gets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;atoi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;name?&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;add_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;id?&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;find_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;atoi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)));&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;user: %s&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;unknown&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;id?&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;find_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;atoi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)));&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;delete_user&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;id unknown&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;delete_all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;sort_by_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;sort_by_id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;print_users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;num_users&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HASH_COUNT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;there are %u users&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num_users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;running&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;delete_all&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;  &lt;span class=&quot;cm&quot;&gt;/* free any structures */&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;键值的各种类型举例&quot;&gt;键值的各种类型举例&lt;/h1&gt;

&lt;h2 id=&quot;整型键值&quot;&gt;整型键值&lt;/h2&gt;

&lt;p&gt;  当键值为整型时，可以使用HASH_ADD_INT和HASH_FIND_INT。（对于所有类型的键，其他操作（例如HASH_DELETE和）HASH_SORT都是相同的）。&lt;/p&gt;

&lt;h2 id=&quot;字符串键值&quot;&gt;字符串键值&lt;/h2&gt;

&lt;p&gt;  当键值为字符串时，具体要使用那个函数取决于结构体中的键值为字符串数组还是字符串指针。 &lt;strong&gt;这一点很重要&lt;/strong&gt;。当结构体中的键值为字符串数组时，使用HASH_ADD_STR。键值为字符串指针时使用HASH_ADD_KEYPTR。接下来给出两个例子参考。&lt;/p&gt;

&lt;p&gt;  当结构体中的键值为字符串数组时&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;  /* strcpy */&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;  /* malloc */&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;   /* printf */&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&quot;uthash.h&quot;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;             &lt;span class=&quot;cm&quot;&gt;/* key (string is WITHIN the structure) */&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;UT_hash_handle&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;         &lt;span class=&quot;cm&quot;&gt;/* makes this structure hashable */&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;


&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;joe&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;bob&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;betty&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;strcpy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;HASH_ADD_STR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;HASH_FIND_STR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;betty&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;betty&apos;s id is %d&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;cm&quot;&gt;/* free the hash table contents */&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HASH_ITER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;HASH_DEL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;free&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;  当结构体中的键值为字符串指针时&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;string.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;  /* strcpy */&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;  /* malloc */&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;   /* printf */&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&quot;uthash.h&quot;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;          &lt;span class=&quot;cm&quot;&gt;/* key */&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;UT_hash_handle&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;         &lt;span class=&quot;cm&quot;&gt;/* makes this structure hashable */&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;


&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;joe&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;bob&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;betty&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;my_struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;HASH_ADD_KEYPTR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strlen&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;HASH_FIND_STR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;betty&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;betty&apos;s id is %d&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;cm&quot;&gt;/* free the hash table contents */&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HASH_ITER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;HASH_DEL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;free&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;指针键值&quot;&gt;指针键值&lt;/h2&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&quot;uthash.h&quot;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;UT_hash_handle&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;el_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;el_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hash&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;someaddr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;el_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;el_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;el_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;someaddr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;HASH_ADD_PTR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;HASH_FIND_PTR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;someaddr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;found&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;cm&quot;&gt;/* release memory */&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;HASH_DEL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;free&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;结构体键值&quot;&gt;结构体键值&lt;/h2&gt;

&lt;p&gt;  在将项目添加到哈希或查找项目之前，必须将结构体键值中的元素清零。&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;stdlib.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
#include&lt;/span&gt; &lt;span class=&quot;cpf&quot;&gt;&quot;uthash.h&quot;&lt;/span&gt;&lt;span class=&quot;cp&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;record_key_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;record_key_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;cm&quot;&gt;/* ... other data ... */&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;UT_hash_handle&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;record_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;argc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;record_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;records&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;record_t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;malloc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;cm&quot;&gt;/*结构体键值清零*/&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;memset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos;a&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HASH_ADD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;records&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;record_key_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;memset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;record_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos;a&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;HASH_FIND&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;records&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;l&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;record_key_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;printf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;found %c %d&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;HASH_ITER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;records&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;HASH_DEL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;records&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;free&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;常用宏参考&quot;&gt;常用宏参考&lt;/h1&gt;

&lt;h2 id=&quot;类型宏&quot;&gt;类型宏&lt;/h2&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;HASH_ADD_INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keyfield_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_REPLACE_INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keyfiled_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;replaced_item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_FIND_INT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_ADD_STR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keyfield_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_REPLACE_STR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keyfield_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replaced_item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_FIND_STR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_ADD_PTR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keyfield_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_REPLACE_PTR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keyfield_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replaced_item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_FIND_PTR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_DEL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_SORT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_COUNT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;通用宏&quot;&gt;通用宏&lt;/h2&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;HASH_ADD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keyfield_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_ADD_BYHASHVALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keyfield_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_ADD_KEYPTR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_ADD_KEYPTR_BYHASHVALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_ADD_INORDER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keyfield_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_ADD_BYHASHVALUE_INORDER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keyfield_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_ADD_KEYPTR_INORDER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_ADD_KEYPTR_BYHASHVALUE_INORDER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_REPLACE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keyfield_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replaced_item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_REPLACE_BYHASHVALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keyfield_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replaced_item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_REPLACE_INORDER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keyfield_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replaced_item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_REPLACE_BYHASHVALUE_INORDER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keyfield_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replaced_item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_FIND&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_FIND_BYHASHVALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_DELETE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_VALUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key_len&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hashv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_SRT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_CNT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_CLEAR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_SELECT&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dst_hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dst_head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;src_hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;src_head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;condition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_ITER&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tmp_item_ptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;HASH_OVERHEAD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hh_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;参数说明&quot;&gt;参数说明&lt;/h2&gt;

&lt;p&gt;  参数说明
  &lt;strong&gt;hh_name&lt;/strong&gt;
  UT_hash_handle结构中字段的 名称。俗称 hh。&lt;/p&gt;

&lt;p&gt;  &lt;strong&gt;head&lt;/strong&gt;
  结构指针变量，用作哈希的“头”。如此命名是因为它最初指向添加到哈希中的第一项。&lt;/p&gt;

&lt;p&gt;  &lt;strong&gt;keyfield_name&lt;/strong&gt;
  结构中键字段的名称。（对于多字段键，这是键的第一个字段）。如果您不熟悉宏，则将字段名称作为参数传递似乎很奇怪。请参阅 注释。&lt;/p&gt;

&lt;p&gt;  &lt;strong&gt;key_len&lt;/strong&gt;
  键字段的长度（以字节为单位）。例如，对于整数键，它是 sizeof(int)，而对于字符串键，它是strlen(key)。（有关多字段键，请参阅此注释。）&lt;/p&gt;

&lt;p&gt;  &lt;strong&gt;key_ptr&lt;/strong&gt;
  对于HASH_FIND，这是指向要在哈希中查找的键的指针（由于它是指针，因此您不能在此处直接传递文字值）。对于 HASH_ADD_KEYPTR，这是要添加的项的键的地址。&lt;/p&gt;

&lt;p&gt;  &lt;strong&gt;hashv&lt;/strong&gt;
  提供的键的哈希值。这是…_BYHASHVALUE宏的输入参数，是 的输出参数HASH_VALUE。如果您要重复查找相同的键，则重用缓存的哈希值可以优化性能。&lt;/p&gt;

&lt;p&gt;  &lt;strong&gt;item_ptr&lt;/strong&gt;
  指向要添加，删除，替换或查找的结构的指针，或迭代期间的当前指针。这是一个输入参数HASH_ADD， HASH_DELETE和HASH_REPLACE宏，和用于输出参数HASH_FIND 和HASH_ITER。（当HASH_ITER用于迭代时，tmp_item_ptr 是与item_ptr内部使用的类型相同的另一个变量）。&lt;/p&gt;

&lt;p&gt;  &lt;strong&gt;replace_item_ptr&lt;/strong&gt;
  用于HASH_REPLACE宏。这是一个输出参数，设置为指向替换的项目（如果没有替换的项目，则设置为NULL）。&lt;/p&gt;

&lt;p&gt;  &lt;strong&gt;cmp&lt;/strong&gt;
  指向比较函数的指针，该函数接受两个参数（指向要比较的项目的指针），并返回一个int值，该值指定第一个项目应在第二个项目之前，等于还是之后排序（如strcmp）。&lt;/p&gt;

&lt;p&gt;  &lt;strong&gt;condition&lt;/strong&gt;
  接受单个参数的函数或宏（指向结构的空指针，需要将其强制转换为适当的结构类型）。如果应“选择”结构以将其添加到目标哈希中，则函数或宏的值应为非零值。&lt;/p&gt;

</description>
        <pubDate>Mon, 28 Feb 2022 00:00:00 +0000</pubDate>
        <link>https://ljw718.github.io//2022/02/28/How-to-use-UThash/</link>
        <guid isPermaLink="true">https://ljw718.github.io//2022/02/28/How-to-use-UThash/</guid>
        
        
      </item>
    
      <item>
        <title>常用Git命令</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#1git工作流程&quot; id=&quot;markdown-toc-1git工作流程&quot;&gt;1、Git工作流程&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2git工作区暂存区和版本库&quot; id=&quot;markdown-toc-2git工作区暂存区和版本库&quot;&gt;2、Git工作区、暂存区和版本库&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3git常用命令&quot; id=&quot;markdown-toc-3git常用命令&quot;&gt;3、Git常用命令&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#git创建仓库命令&quot; id=&quot;markdown-toc-git创建仓库命令&quot;&gt;git创建仓库命令&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#提交与修改&quot; id=&quot;markdown-toc-提交与修改&quot;&gt;提交与修改&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#提交日志&quot; id=&quot;markdown-toc-提交日志&quot;&gt;提交日志&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#远程操作&quot; id=&quot;markdown-toc-远程操作&quot;&gt;远程操作&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#4git常见问题&quot; id=&quot;markdown-toc-4git常见问题&quot;&gt;4、Git常见问题&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#openssl-ssl_read-connection-was-reset-errno-10054&quot; id=&quot;markdown-toc-openssl-ssl_read-connection-was-reset-errno-10054&quot;&gt;OpenSSL SSL_read: Connection was reset, errno 10054&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;1git工作流程&quot;&gt;1、Git工作流程&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/Git/git-process.png&quot; alt=&quot;git-process&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;2git工作区暂存区和版本库&quot;&gt;2、Git工作区、暂存区和版本库&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;工作区：&lt;/strong&gt;就是你在电脑里能看到的目录。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;暂存区：&lt;/strong&gt;英文叫 stage 或 index。一般存放在 &lt;strong&gt;.git&lt;/strong&gt; 目录下的 index 文件（.git/index）中，所以我们把暂存区有时也叫作索引（index）。&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;版本库：&lt;/strong&gt;工作区有一个隐藏目录 &lt;strong&gt;.git&lt;/strong&gt;，这个不算工作区，而是 Git 的版本库。&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/Git/work-stage.jpg&quot; alt=&quot;img&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;图中左侧为工作区，右侧为版本库。在版本库中标记为 “index” 的区域是暂存区（stage/index），标记为 “master” 的是 master 分支所代表的目录树。&lt;/li&gt;
  &lt;li&gt;图中我们可以看出此时 “HEAD” 实际是指向 master 分支的一个”游标”。所以图示的命令中出现 HEAD 的地方可以用 master 来替换。&lt;/li&gt;
  &lt;li&gt;图中的 objects 标识的区域为 Git 的对象库，实际位于 “.git/objects” 目录下，里面包含了创建的各种对象及内容。&lt;/li&gt;
  &lt;li&gt;当对工作区修改（或新增）的文件执行 &lt;strong&gt;git add&lt;/strong&gt; 命令时，暂存区的目录树被更新，同时工作区修改（或新增）的文件内容被写入到对象库中的一个新的对象中，而该对象的ID被记录在暂存区的文件索引中。&lt;/li&gt;
  &lt;li&gt;当执行提交操作（git commit）时，暂存区的目录树写到版本库（对象库）中，master 分支会做相应的更新。即 master 指向的目录树就是提交时暂存区的目录树。&lt;/li&gt;
  &lt;li&gt;当执行 &lt;strong&gt;git reset HEAD&lt;/strong&gt; 命令时，暂存区的目录树会被重写，被 master 分支指向的目录树所替换，但是工作区不受影响。&lt;/li&gt;
  &lt;li&gt;当执行 **git rm –cached &lt;file&gt;** 命令时，会直接从暂存区删除文件，工作区则不做出改变。&lt;/file&gt;&lt;/li&gt;
  &lt;li&gt;当执行 &lt;strong&gt;git checkout .&lt;/strong&gt; 或者 **git checkout – &lt;file&gt;** 命令时，会用暂存区全部或指定的文件替换工作区的文件。这个操作很危险，会清除工作区中未添加到暂存区中的改动。&lt;/file&gt;&lt;/li&gt;
  &lt;li&gt;当执行 &lt;strong&gt;git checkout HEAD .&lt;/strong&gt; 或者 **git checkout HEAD &lt;file&gt;** 命令时，会用 HEAD 指向的 master 分支中的全部或者部分文件替换暂存区和以及工作区中的文件。这个命令也是极具危险性的，因为不但会清除工作区中未提交的改动，也会清除暂存区中未提交的改动。&lt;/file&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;3git常用命令&quot;&gt;3、Git常用命令&lt;/h2&gt;

&lt;p&gt;Git 常用的是以下 6 个命令：&lt;strong&gt;git clone&lt;/strong&gt;、&lt;strong&gt;git push&lt;/strong&gt;、&lt;strong&gt;git add&lt;/strong&gt; 、&lt;strong&gt;git commit&lt;/strong&gt;、&lt;strong&gt;git checkout&lt;/strong&gt;、&lt;strong&gt;git pull&lt;/strong&gt;。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/Git/git-command.jpg&quot; alt=&quot;git-command&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;说明：&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;workspace：工作区&lt;/li&gt;
  &lt;li&gt;staging area：暂存区/缓存区&lt;/li&gt;
  &lt;li&gt;local repository：版本库或本地仓库&lt;/li&gt;
  &lt;li&gt;remote repository：远程仓库&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;一个简单的操作步骤：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ git init                        - 初始化仓库。
$ git add .                       - 添加文件到暂存区。
$ git commit                      - 将暂存区内容添加到仓库中。
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;git创建仓库命令&quot;&gt;git创建仓库命令&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;命令&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;说明&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git init&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;初始化仓库&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git clone&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;拷贝一份远程仓库，也就是下载一个项目。&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;提交与修改&quot;&gt;提交与修改&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;命令&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;说明&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git add&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;添加文件到仓库&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git status&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;查看仓库当前的状态，显示有变更的文件。&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git diff&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;比较文件的不同，即暂存区和工作区的差异。&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git commit&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;提交暂存区到本地仓库。&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git reset&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;回退版本。&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git rm&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;删除工作区文件。&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git mv&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;移动或重命名工作区文件。&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;提交日志&quot;&gt;提交日志&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;命令&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;说明&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git log&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;查看历史提交记录&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git blame &amp;lt;file&amp;gt;&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;以列表形式查看指定文件的历史修改记录&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git reflog&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;查看所有分支的所有操作记录&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;远程操作&quot;&gt;远程操作&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;命令&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;说明&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git remote&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;远程仓库操作&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git fetch&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;从远程获取代码库&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git pull&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;下载远程代码并合并&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git push&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;上传远程代码并合并&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;4git常见问题&quot;&gt;4、Git常见问题&lt;/h2&gt;

&lt;h3 id=&quot;openssl-ssl_read-connection-was-reset-errno-10054&quot;&gt;OpenSSL SSL_read: Connection was reset, errno 10054&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/Git/2021-08-20_01-01-37.png&quot; alt=&quot;ssl-error&quot; /&gt;’’&lt;/p&gt;

&lt;p&gt;解决方案： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git config --global http.sslVerify &quot;false&quot;&lt;/code&gt;&lt;/p&gt;
</description>
        <pubDate>Sun, 22 Aug 2021 04:08:00 +0000</pubDate>
        <link>https://ljw718.github.io//2021/08/22/Git-command/</link>
        <guid isPermaLink="true">https://ljw718.github.io//2021/08/22/Git-command/</guid>
        
        
        <category>Git</category>
        
      </item>
    
      <item>
        <title>LeetCode刷题常用算法思路与框架</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#1二分查找&quot; id=&quot;markdown-toc-1二分查找&quot;&gt;1、二分查找&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2双指针&quot; id=&quot;markdown-toc-2双指针&quot;&gt;2、双指针&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3滑动窗口&quot; id=&quot;markdown-toc-3滑动窗口&quot;&gt;3、滑动窗口&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#4深度优先搜索dfs&quot; id=&quot;markdown-toc-4深度优先搜索dfs&quot;&gt;4、深度优先搜索（DFS）&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;总结&lt;a href=&quot;https://leetcode-cn.com/problemset/all/&quot;&gt;LeetCode&lt;/a&gt;刷题过程中常用的算法，以及整理部分算法思路框架，并且以伪代码实现&lt;/p&gt;

&lt;h2 id=&quot;1二分查找&quot;&gt;1、二分查找&lt;/h2&gt;
&lt;p&gt;算法思路：从中间开始找，中间值等于目标值，返回true，中间值小于目标值，则从中间值右边开始查找，否则， 从中间值左边开始查找，直到找到目标返回，否则返回false。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;nums = [1,2,3,4,5,6,...,n], size = n, target = x
int left = 0;
int right = n - 1;
int mid = 0;
while (left &amp;lt;= right) {
	mid = left + (right - left)/2
	if (nums[mid] == target) {
		return true;
	} else if(nums[mid] &amp;lt; target) {
		left = mid + 1;
	} else {
		right = mid
	}
}
return false
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;2双指针&quot;&gt;2、双指针&lt;/h2&gt;
&lt;p&gt;算法思路：涉及一维数组，大部分是双指针一个在左，一个在右，多维数组，都从左边开始，满足条件的指针先动。&lt;/p&gt;

&lt;p&gt;LeetCode第11题：  &lt;a href=&quot;https://leetcode-cn.com/problems/container-with-most-water/&quot;&gt;盛最多水的容器&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;nums = [1,7,3,5,5,6,7,8.6,2]   size = n, target = x

int left = 0;
int right = size - 1;
int x = 1;
int min = 0;
int max = 0;
while (left &amp;lt; right) {
	min = MIN(nums[left], nums[right]);
	max = MAX(max, min * (right, - left));
	if (nums[left] &amp;lt; nums[right]) {
		++left;
	}
	++right;
}
return max;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;3滑动窗口&quot;&gt;3、滑动窗口&lt;/h2&gt;

&lt;p&gt;算法思路：定义两个索引left和right, 开始都指向窗口起始位置，先移动right,改变窗口大小，此时检查窗口内部的数据是否满足待测条件， 不满足窗口继续向右移动， 若满足；计算窗口内部的数据，left右移。&lt;/p&gt;

&lt;p&gt;LeetCode第209题：&lt;a href=&quot;https://leetcode-cn.com/problems/minimum-size-subarray-sum/&quot;&gt;长度最小的子数组&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;nums = [1,2,3,4,5,6,7,8...,n]   size = n, target = x
int left = 0;
int right = 0;
int x = 1;
while (right &amp;lt; size) {
	x *= nums[right];
	while (x &amp;gt;= targht) {
		// 省略处理过程
		++left;
	}
	++right;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;4深度优先搜索dfs&quot;&gt;4、深度优先搜索（DFS）&lt;/h2&gt;

&lt;p&gt;算法思路：从起始节点开始搜索，到下一个节点，判断其是否满足退出条件（搜索到末尾了）。如果到达末尾，此时进行数据相关处理，否则，一直搜索下去。&lt;/p&gt;

&lt;p&gt;LeetCode第797题：&lt;a href=&quot;https://leetcode-cn.com/problems/all-paths-from-source-to-target/&quot;&gt;所有可能的路径&lt;/a&gt;
LeetCode第200题：&lt;a href=&quot;https://leetcode-cn.com/problems/number-of-islands/&quot;&gt;岛屿数量&lt;/a&gt;
LeetCode第797题：&lt;a href=&quot;https://leetcode-cn.com/problems/number-of-provinces/&quot;&gt;省份数量&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// 第797题：省份数量：
void DFS(int **isConnected, int *visted, int provence, int i) {
    for (int j = 0; j &amp;lt; provence; j++) {
        if (isConnected[i][j] == 1 &amp;amp;&amp;amp; visted[j] == 0) {
            visted[j] = 1;
            DFS(isConnected, visted, provence, j);
        }
    }
    return;
}

int findCircleNum(int** isConnected, int isConnectedSize, int* isConnectedColSize){
    int provence = isConnectedSize;
    int *visted = (int *)malloc(sizeof(int) * provence);
    memset(visted, 0, sizeof(int) * provence);

    int cnt = 0;
    for (int i = 0; i &amp;lt; provence; i++) {
        if (visted[i] != 1) {
            DFS(isConnected, visted, provence, i);
            cnt++;
        }
    }
    return cnt;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
        <pubDate>Thu, 19 Aug 2021 14:08:00 +0000</pubDate>
        <link>https://ljw718.github.io//2021/08/19/Algorithms/</link>
        <guid isPermaLink="true">https://ljw718.github.io//2021/08/19/Algorithms/</guid>
        
        <category>常用算法思路与框架</category>
        
        
        <category>LeetCode</category>
        
      </item>
    
      <item>
        <title>GDB分析进程占用CPU过高问题</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#1查看cpu与进程id&quot; id=&quot;markdown-toc-1查看cpu与进程id&quot;&gt;1、查看CPU与进程ID&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2查看线程pid占用cpu情况&quot; id=&quot;markdown-toc-2查看线程pid占用cpu情况&quot;&gt;2、查看线程pid占用CPU情况&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3attach到相关进程&quot; id=&quot;markdown-toc-3attach到相关进程&quot;&gt;3、attach到相关进程&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#4查看线程信息&quot; id=&quot;markdown-toc-4查看线程信息&quot;&gt;4、查看线程信息&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#5查看线程号对应的线程id&quot; id=&quot;markdown-toc-5查看线程号对应的线程id&quot;&gt;5、查看线程号对应的线程ID&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#6根据线程id切换线程&quot; id=&quot;markdown-toc-6根据线程id切换线程&quot;&gt;6、根据线程ID切换线程&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#7查看函数调用栈&quot; id=&quot;markdown-toc-7查看函数调用栈&quot;&gt;7、查看函数调用栈&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#8根据调用函数分析源代码&quot; id=&quot;markdown-toc-8根据调用函数分析源代码&quot;&gt;8、根据调用函数分析源代码&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;重点是查看进程的线程中，哪个线程占用cpu过高，然后用gdb附加到进程，调试线程，看是否有死循环或者死锁等问题。
调试步骤参考如下：&lt;/p&gt;

&lt;h2 id=&quot;1查看cpu与进程id&quot;&gt;1、查看CPU与进程ID&lt;/h2&gt;
&lt;p&gt;先用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;top&lt;/code&gt;查看CPU使用情况，再用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ps + grep&lt;/code&gt;找出该死的进程pid，比如 36625&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/Linux/gdb-pthread/1.png&quot; alt=&quot;p1&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;2查看线程pid占用cpu情况&quot;&gt;2、查看线程pid占用CPU情况&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;top -H -p 36625&lt;/code&gt;，(top然后shift+H可以看出某个线程，左上角有提示：thread on 则为可查看线程)所有该进程的线程都列出来， 看看哪个线程pid占用cpu最多，记下对应的线程号，如：36643
&lt;img src=&quot;/styles/images/Linux/gdb-pthread/2.png&quot; alt=&quot;p2&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;3attach到相关进程&quot;&gt;3、attach到相关进程&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gdb attach&lt;/code&gt; 到进程号码（36625）
&lt;img src=&quot;/styles/images/Linux/gdb-pthread/3.png&quot; alt=&quot;p3&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;4查看线程信息&quot;&gt;4、查看线程信息&lt;/h2&gt;
&lt;p&gt;（仍然在gdb中） &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;info threads&lt;/code&gt; 结果大致如下：
&lt;img src=&quot;/styles/images/Linux/gdb-pthread/4.png&quot; alt=&quot;p4&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;5查看线程号对应的线程id&quot;&gt;5、查看线程号对应的线程ID&lt;/h2&gt;
&lt;p&gt;找到线程号码对应的thread（LWP 36643）即是我们刚刚记下的线程号
&lt;img src=&quot;/styles/images/Linux/gdb-pthread/5.png&quot; alt=&quot;p5&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;6根据线程id切换线程&quot;&gt;6、根据线程ID切换线程&lt;/h2&gt;
&lt;p&gt;（仍然在gdb中）&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;thread  线程号码切换到线程（2）&lt;/code&gt;–这里在info threads显示出来的序号需要使用gdb能识别的线程序号，即执行：thread 2 切换到我们刚刚记下的线程号：36643的对应线程，如下：
&lt;img src=&quot;/styles/images/Linux/gdb-pthread/6.png&quot; alt=&quot;p6&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;7查看函数调用栈&quot;&gt;7、查看函数调用栈&lt;/h2&gt;
&lt;p&gt;（仍然在gdb中）&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bt&lt;/code&gt; 查看线程调用堆栈 
&lt;img src=&quot;/styles/images/Linux/gdb-pthread/7.png&quot; alt=&quot;p7&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;8根据调用函数分析源代码&quot;&gt;8、根据调用函数分析源代码&lt;/h2&gt;
&lt;p&gt;从上面输出的信息，基本上可以查看线程对应的代码断，是否有死循环等，如果是死锁的话，需要多次查看当前线程堆栈，或者查看全部线程的堆栈，总是会有某些个线程跟其他线程不一致，然后再对应到代码来进行定位解决
&lt;img src=&quot;/styles/images/Linux/gdb-pthread/8.png&quot; alt=&quot;p8&quot; /&gt;&lt;/p&gt;

&lt;p&gt;代码中此处陷入死循环。&lt;/p&gt;
</description>
        <pubDate>Tue, 13 Aug 2019 14:08:00 +0000</pubDate>
        <link>https://ljw718.github.io//2019/08/13/LinuxDebugPthread/</link>
        <guid isPermaLink="true">https://ljw718.github.io//2019/08/13/LinuxDebugPthread/</guid>
        
        <category>GDB调试</category>
        
        
        <category>Linux</category>
        
      </item>
    
      <item>
        <title>程序猿颈椎保健操</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#程序猿颈椎保健操&quot; id=&quot;markdown-toc-程序猿颈椎保健操&quot;&gt;&lt;strong&gt;程序猿颈椎保健操&lt;/strong&gt;&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#一双掌擦颈&quot; id=&quot;markdown-toc-一双掌擦颈&quot;&gt;一、双掌擦颈。&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#二左顾右盼&quot; id=&quot;markdown-toc-二左顾右盼&quot;&gt;二、左顾右盼。&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#三前后点头&quot; id=&quot;markdown-toc-三前后点头&quot;&gt;三、前后点头。&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#四旋肩舒颈&quot; id=&quot;markdown-toc-四旋肩舒颈&quot;&gt;四、旋肩舒颈。&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#五颈项争力&quot; id=&quot;markdown-toc-五颈项争力&quot;&gt;五、颈项争力。&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#六摇头晃脑&quot; id=&quot;markdown-toc-六摇头晃脑&quot;&gt;六、摇头晃脑。&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#七头手相抗&quot; id=&quot;markdown-toc-七头手相抗&quot;&gt;七、头手相抗。&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#八仰头望掌&quot; id=&quot;markdown-toc-八仰头望掌&quot;&gt;八、仰头望掌。&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;这套颈椎保健操,适合在电脑前久坐工作的小伙伴&lt;/p&gt;

&lt;h1 id=&quot;程序猿颈椎保健操&quot;&gt;&lt;strong&gt;程序猿颈椎保健操&lt;/strong&gt;&lt;/h1&gt;
&lt;h2 id=&quot;一双掌擦颈&quot;&gt;一、双掌擦颈。&lt;/h2&gt;
&lt;p&gt;方法：用左手掌来回摩擦颈部，口中默念八下后，开始捏后颈，然后换右手，有助于颈部放松。&lt;br /&gt;
&lt;img src=&quot;/styles/images/healthy/1.png&quot; alt=&quot;p1&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;二左顾右盼&quot;&gt;二、左顾右盼。&lt;/h2&gt;
&lt;p&gt;方法：头向左转90度，停留3秒，再向右转，停留3秒，做两个8拍。  &lt;br /&gt;
&lt;img src=&quot;/styles/images/healthy/2.png&quot; alt=&quot;p2&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;三前后点头&quot;&gt;三、前后点头。&lt;/h2&gt;
&lt;p&gt;方法：把颈尽量向前伸，停留3秒，再向后仰，停留3秒，做两个8拍。&lt;br /&gt;
&lt;img src=&quot;/styles/images/healthy/3.png&quot; alt=&quot;p3&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;四旋肩舒颈&quot;&gt;四、旋肩舒颈。&lt;/h2&gt;
&lt;p&gt;方法：双手放在肩部，掌心向下，两臂先由后向前旋转20-30次，再由前向后旋转20-30次。&lt;br /&gt;
&lt;img src=&quot;/styles/images/healthy/4.png&quot; alt=&quot;p4&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;五颈项争力&quot;&gt;五、颈项争力。&lt;/h2&gt;
&lt;p&gt;方法：左手放在背后，右手手臂放在胸前，手掌立起向左平行推出，同时头部向右看，保持几秒钟，再换左右手。&lt;br /&gt;
&lt;img src=&quot;/styles/images/healthy/5.png&quot; alt=&quot;p5&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;六摇头晃脑&quot;&gt;六、摇头晃脑。&lt;/h2&gt;
&lt;p&gt;方法：左右、前后，360度旋转5次，再反方向旋转5次。&lt;br /&gt;
&lt;img src=&quot;/styles/images/healthy/6.png&quot; alt=&quot;p6&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;七头手相抗&quot;&gt;七、头手相抗。&lt;/h2&gt;
&lt;p&gt;方法：双手交叉仅仅贴颈后，用力顶头颈，头颈向后用力，互相抵抗5次。&lt;br /&gt;
&lt;img src=&quot;/styles/images/healthy/7.png&quot; alt=&quot;p7&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;八仰头望掌&quot;&gt;八、仰头望掌。&lt;/h2&gt;
&lt;p&gt;方法：双手上举过头，手指交叉，掌心向上，将头扬起向上看手背，保持5秒。&lt;br /&gt;
&lt;img src=&quot;/styles/images/healthy/8.png&quot; alt=&quot;p8&quot; /&gt;&lt;/p&gt;

</description>
        <pubDate>Tue, 13 Aug 2019 12:20:00 +0000</pubDate>
        <link>https://ljw718.github.io//2019/08/13/CervicalHealthExercise/</link>
        <guid isPermaLink="true">https://ljw718.github.io//2019/08/13/CervicalHealthExercise/</guid>
        
        <category>健康操</category>
        
        
        <category>健康</category>
        
      </item>
    
      <item>
        <title>Sublime Text3使用技巧</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#1package-control快速安装&quot; id=&quot;markdown-toc-1package-control快速安装&quot;&gt;1、Package Control快速安装&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2package-control使用&quot; id=&quot;markdown-toc-2package-control使用&quot;&gt;2、Package Control使用&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#3解决unable-to-download-xxx问题&quot; id=&quot;markdown-toc-3解决unable-to-download-xxx问题&quot;&gt;3、解决Unable to download XXX问题&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#4安装常用插件&quot; id=&quot;markdown-toc-4安装常用插件&quot;&gt;4、安装常用插件&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#41--localization-汉化&quot; id=&quot;markdown-toc-41--localization-汉化&quot;&gt;4.1  Localization [汉化]&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#42--docblockr-生成注释&quot; id=&quot;markdown-toc-42--docblockr-生成注释&quot;&gt;4.2  Doc​Blockr [生成注释]&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#43--autofilename-自动完成文件路径&quot; id=&quot;markdown-toc-43--autofilename-自动完成文件路径&quot;&gt;4.3  AutoFileName [自动完成文件路径]&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#44--ctags-函数跳转&quot; id=&quot;markdown-toc-44--ctags-函数跳转&quot;&gt;4.4  CTags [函数跳转]&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#44--astyleformatter-cc等编码风格格式器&quot; id=&quot;markdown-toc-44--astyleformatter-cc等编码风格格式器&quot;&gt;4.4  AStyleFormatter [C/C++等编码风格格式器]&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#45--converttoutf8--中文乱码解决包&quot; id=&quot;markdown-toc-45--converttoutf8--中文乱码解决包&quot;&gt;4.5  ConvertToUTF8  [中文乱码解决包]&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#5卸载不常用插件&quot; id=&quot;markdown-toc-5卸载不常用插件&quot;&gt;5、卸载不常用插件&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Sublime Text3使用技巧及其常见问题解决办法&lt;/p&gt;

&lt;h1 id=&quot;1package-control快速安装&quot;&gt;1、Package Control快速安装&lt;/h1&gt;

&lt;p&gt;通过View-&amp;gt;Show Console菜单打开命令行&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/SublimeText3/Snipaste_2019-08-13_10-53-42-p1.jpg&quot; alt=&quot;图1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/SublimeText3/Snipaste_2019-08-13_11-02-50-p2.jpg&quot; alt=&quot;图2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;粘贴如下代码(注意下面代码为一行)：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;import urllib.request,os; pf = &apos;Package Control.sublime-package&apos;; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); open(os.path.join(ipp, pf), &apos;wb&apos;).write(urllib.request.urlopen( &apos;http://sublime.wbond.net/&apos; + pf.replace(&apos; &apos;,&apos;%20&apos;)).read())
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;按下enter键,稍等即可, 
安装完毕后,重启sublime，此时就可以在Preferences菜单下看到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Package Settings&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Package Control&lt;/code&gt;两个菜单了。&lt;/p&gt;

&lt;h1 id=&quot;2package-control使用&quot;&gt;2、Package Control使用&lt;/h1&gt;

&lt;p&gt;打开命令行,快捷键为：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl + Shift + p&lt;/code&gt;,输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pci&lt;/code&gt;(点击Package Control:Install Packge选项),几秒钟后弹出插件管理页面,输入想要安装的插件名称,以&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ctags&lt;/code&gt;为例&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/SublimeText3/Snipaste_2019-08-13_11-15-14-p3.png&quot; alt=&quot;图3&quot; /&gt;&lt;/p&gt;

&lt;p&gt;按回车即可安装。&lt;/p&gt;

&lt;h1 id=&quot;3解决unable-to-download-xxx问题&quot;&gt;3、解决Unable to download XXX问题&lt;/h1&gt;

&lt;p&gt;Sublime Text3 安装插件报错：&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Package Control&lt;/code&gt;&lt;br /&gt;
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Unable to download XXX. Please view the console for more details.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;解决方法：
Preferences &amp;gt; Package Settings &amp;gt; Package Control &amp;gt; Settings-User
&lt;img src=&quot;/styles/images/SublimeText3/Snipaste_2019-08-13_11-42-53-p4.png&quot; alt=&quot;图4&quot; /&gt;&lt;/p&gt;

&lt;p&gt;增加如下内容：&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&quot;debug&quot;: true,
&quot;downloader_precedence&quot;:
{
    &quot;linux&quot;: [ &quot;curl&quot;, &quot;urllib&quot;, &quot;wget&quot; ],
    &quot;osx&quot;: [ &quot;curl&quot;, &quot;urllib&quot; ],
    &quot;windows&quot;: [ &quot;wininet&quot; ]
},
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;调整格式后内容如下：&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;{
	&quot;bootstrapped&quot;: true,
	&quot;debug&quot;: true,
	&quot;downloader_precedence&quot;:
	{
		&quot;linux&quot;:
		[
			&quot;curl&quot;,
			&quot;urllib&quot;,
			&quot;wget&quot;
		],
		&quot;osx&quot;:
		[
			&quot;curl&quot;,
			&quot;urllib&quot;
		],
		&quot;windows&quot;:
		[
			&quot;wininet&quot;
		]
	},
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;再次安装插件就OK了。&lt;/p&gt;

&lt;h1 id=&quot;4安装常用插件&quot;&gt;4、安装常用插件&lt;/h1&gt;

&lt;h2 id=&quot;41--localization-汉化&quot;&gt;4.1  Localization [汉化]&lt;/h2&gt;
&lt;p&gt;使用：安装后，点击help-&amp;gt;languaremove packagege-&amp;gt;相应语言版本&lt;br /&gt;
&lt;img src=&quot;/styles/images/SublimeText3/Snipaste_2019-08-13_12-49-03-p5.png&quot; alt=&quot;图5&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;42--docblockr-生成注释&quot;&gt;4.2  Doc​Blockr [生成注释]&lt;/h2&gt;
&lt;p&gt;使用：输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/**&lt;/code&gt;,然后按Tab键,该插件就会自动解析任何功能,并准备合适的模板 &lt;br /&gt;
自定义注释：Preferences &amp;gt; Package Settings &amp;gt; DocBlockr &amp;gt; Settings-User
&lt;img src=&quot;/styles/images/SublimeText3/Snipaste_2019-08-13_13-02-28-p6.png&quot; alt=&quot;图6&quot; /&gt;
输入&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;{
    //自定义配置
    &quot;jsdocs_extra_tags&quot;: [
                    &quot;@Author liujw&quot;,
                    &quot;@DateTime &quot;,
                    &quot;@FuncName: &quot;,
                ],

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h2 id=&quot;43--autofilename-自动完成文件路径&quot;&gt;4.3  AutoFileName [自动完成文件路径]&lt;/h2&gt;

&lt;h2 id=&quot;44--ctags-函数跳转&quot;&gt;4.4  CTags [函数跳转]&lt;/h2&gt;
&lt;p&gt;CTags58.zip下载链接&lt;a href=&quot;https://pan.baidu.com/s/18uYw4b6uX4_DffdJShfoug&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://pan.baidu.com/s/18uYw4b6uX4_DffdJShfoug&lt;/code&gt;&lt;/a&gt;[提取码：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ge06&lt;/code&gt;]&lt;br /&gt;
参考步骤 &lt;a href=&quot;https://www.jianshu.com/p/9f5801e83c6c&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://www.jianshu.com/p/9f5801e83c6c&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;44--astyleformatter-cc等编码风格格式器&quot;&gt;4.4  AStyleFormatter [C/C++等编码风格格式器]&lt;/h2&gt;
&lt;p&gt;使用：找到需要格式化的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.c&lt;/code&gt;文件,快捷键&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl + ALT + F&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;45--converttoutf8--中文乱码解决包&quot;&gt;4.5  ConvertToUTF8  [中文乱码解决包]&lt;/h2&gt;

&lt;h1 id=&quot;5卸载不常用插件&quot;&gt;5、卸载不常用插件&lt;/h1&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl + Shift + p&lt;/code&gt;打开命令行,输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pcrp&lt;/code&gt;(点击Package Control:Remove Packge选项),几秒钟后弹出插件管理页面,选择想要卸载的插件即可。&lt;/p&gt;

</description>
        <pubDate>Mon, 12 Aug 2019 15:08:00 +0000</pubDate>
        <link>https://ljw718.github.io//2019/08/12/SublimeText3Settings/</link>
        <guid isPermaLink="true">https://ljw718.github.io//2019/08/12/SublimeText3Settings/</guid>
        
        <category>Sublime Text3</category>
        
        
        <category>开发工具</category>
        
      </item>
    
      <item>
        <title>Linux常用shell命令汇总</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#系统信息&quot; id=&quot;markdown-toc-系统信息&quot;&gt;系统信息&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#关机-系统的关机重启以及登出-&quot; id=&quot;markdown-toc-关机-系统的关机重启以及登出-&quot;&gt;关机 (系统的关机、重启以及登出 )&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#文件和目录&quot; id=&quot;markdown-toc-文件和目录&quot;&gt;文件和目录&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#文件搜索&quot; id=&quot;markdown-toc-文件搜索&quot;&gt;文件搜索&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#挂载一个文件系统&quot; id=&quot;markdown-toc-挂载一个文件系统&quot;&gt;挂载一个文件系统&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#磁盘空间&quot; id=&quot;markdown-toc-磁盘空间&quot;&gt;磁盘空间&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#用户和群组&quot; id=&quot;markdown-toc-用户和群组&quot;&gt;用户和群组&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#文件的权限---使用--设置权限使用---用于取消&quot; id=&quot;markdown-toc-文件的权限---使用--设置权限使用---用于取消&quot;&gt;文件的权限 - 使用 “+” 设置权限，使用 “-“ 用于取消&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#文件的特殊属性---使用--设置权限使用---用于取消&quot; id=&quot;markdown-toc-文件的特殊属性---使用--设置权限使用---用于取消&quot;&gt;文件的特殊属性 - 使用 “+” 设置权限，使用 “-“ 用于取消&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#打包和压缩文件&quot; id=&quot;markdown-toc-打包和压缩文件&quot;&gt;打包和压缩文件&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#rpm-包---fedora-redhat及类似系统&quot; id=&quot;markdown-toc-rpm-包---fedora-redhat及类似系统&quot;&gt;RPM 包 - （Fedora, Redhat及类似系统）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#yum-软件包升级器---fedora-redhat及类似系统&quot; id=&quot;markdown-toc-yum-软件包升级器---fedora-redhat及类似系统&quot;&gt;YUM 软件包升级器 - （Fedora, RedHat及类似系统）&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#查看文件内容&quot; id=&quot;markdown-toc-查看文件内容&quot;&gt;查看文件内容&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#文本处理&quot; id=&quot;markdown-toc-文本处理&quot;&gt;文本处理&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#字符设置和文件格式转换&quot; id=&quot;markdown-toc-字符设置和文件格式转换&quot;&gt;字符设置和文件格式转换&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#文件系统分析&quot; id=&quot;markdown-toc-文件系统分析&quot;&gt;文件系统分析&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#初始化一个文件系统&quot; id=&quot;markdown-toc-初始化一个文件系统&quot;&gt;初始化一个文件系统&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#swap文件系统&quot; id=&quot;markdown-toc-swap文件系统&quot;&gt;SWAP文件系统&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#备份&quot; id=&quot;markdown-toc-备份&quot;&gt;备份&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#网络---以太网和wifi无线&quot; id=&quot;markdown-toc-网络---以太网和wifi无线&quot;&gt;网络 - （以太网和WIFI无线）&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;文章转载自:  https://www.cnblogs.com/yjd_hycf_space/p/7730690.html&lt;/p&gt;

&lt;h1 id=&quot;系统信息&quot;&gt;系统信息&lt;/h1&gt;
&lt;p&gt;arch 显示机器的处理器架构&lt;br /&gt;
uname -m 显示机器的处理器架构&lt;br /&gt;
uname -r 显示正在使用的内核版本&lt;br /&gt;
dmidecode -q 显示硬件系统部件 - (SMBIOS / DMI) &lt;br /&gt;
hdparm -i /dev/hda 罗列一个磁盘的架构特性 &lt;br /&gt;
hdparm -tT /dev/sda 在磁盘上执行测试性读取操作 &lt;br /&gt;
cat /proc/cpuinfo 显示CPU info的信息 &lt;br /&gt;
cat /proc/interrupts 显示中断 &lt;br /&gt;
cat /proc/meminfo 校验内存使用 &lt;br /&gt;
cat /proc/swaps 显示哪些swap被使用 &lt;br /&gt;
cat /proc/version 显示内核的版本 &lt;br /&gt;
cat /proc/net/dev 显示网络适配器及统计 &lt;br /&gt;
cat /proc/mounts 显示已加载的文件系统 &lt;br /&gt;
lspci -tv 罗列 PCI 设备 &lt;br /&gt;
lsusb -tv 显示 USB 设备 &lt;br /&gt;
date 显示系统日期 &lt;br /&gt;
cal 2007 显示2007年的日历表 &lt;br /&gt;
date 041217002007.00 设置日期和时间 - 月日时分年.秒 &lt;br /&gt;
clock -w 将时间修改保存到 BIOS&lt;/p&gt;

&lt;h1 id=&quot;关机-系统的关机重启以及登出-&quot;&gt;关机 (系统的关机、重启以及登出 )&lt;/h1&gt;
&lt;p&gt;shutdown -h now 关闭系统&lt;br /&gt;
init 0 关闭系统&lt;br /&gt;
telinit 0 关闭系统&lt;br /&gt;
shutdown -h hours:minutes &amp;amp; 按预定时间关闭系统 &lt;br /&gt;
shutdown -c 取消按预定时间关闭系统 &lt;br /&gt;
shutdown -r now 重启&lt;br /&gt;
reboot 重启&lt;br /&gt;
logout 注销&lt;/p&gt;

&lt;h1 id=&quot;文件和目录&quot;&gt;文件和目录&lt;/h1&gt;
&lt;p&gt;cd /home 进入 ‘/ home’ 目录’ &lt;br /&gt;
cd .. 返回上一级目录 &lt;br /&gt;
cd ../.. 返回上两级目录 &lt;br /&gt;
cd 进入个人的主目录 &lt;br /&gt;
cd ~user1 进入个人的主目录&lt;br /&gt;
cd - 返回上次所在的目录 &lt;br /&gt;
pwd 显示工作路径 &lt;br /&gt;
ls 查看目录中的文件 &lt;br /&gt;
ls -F 查看目录中的文件 &lt;br /&gt;
ls -l 显示文件和目录的详细资料 &lt;br /&gt;
ls -a 显示隐藏文件 &lt;br /&gt;
ls &lt;em&gt;[0-9]&lt;/em&gt; 显示包含数字的文件名和目录名 &lt;br /&gt;
tree 显示文件和目录由根目录开始的树形结构&lt;br /&gt;
lstree 显示文件和目录由根目录开始的树形结构&lt;br /&gt;
mkdir dir1 创建一个叫做 ‘dir1’ 的目录’ &lt;br /&gt;
mkdir dir1 dir2 同时创建两个目录 &lt;br /&gt;
mkdir -p /tmp/dir1/dir2 创建一个目录树 &lt;br /&gt;
rm -f file1 删除一个叫做 ‘file1’ 的文件’ &lt;br /&gt;
rmdir dir1 删除一个叫做 ‘dir1’ 的目录’ &lt;br /&gt;
rm -rf dir1 删除一个叫做 ‘dir1’ 的目录并同时删除其内容 &lt;br /&gt;
rm -rf dir1 dir2 同时删除两个目录及它们的内容 &lt;br /&gt;
mv dir1 new_dir 重命名/移动 一个目录 &lt;br /&gt;
cp file1 file2 复制一个文件 &lt;br /&gt;
cp dir/* . 复制一个目录下的所有文件到当前工作目录 &lt;br /&gt;
cp -a /tmp/dir1 . 复制一个目录到当前工作目录 &lt;br /&gt;
cp -a dir1 dir2 复制一个目录 &lt;br /&gt;
ln -s file1 lnk1 创建一个指向文件或目录的软链接 &lt;br /&gt;
ln file1 lnk1 创建一个指向文件或目录的物理链接 &lt;br /&gt;
touch -t 0712250000 file1 修改一个文件或目录的时间戳 - (YYMMDDhhmm) &lt;br /&gt;
file file1 outputs the mime type of the file as text &lt;br /&gt;
iconv -l 列出已知的编码 &lt;br /&gt;
iconv -f fromEncoding -t toEncoding inputFile &amp;gt; outputFile creates a new from the given input file by assuming it is encoded in fromEncoding and converting it to toEncoding.&lt;/p&gt;

&lt;h1 id=&quot;文件搜索&quot;&gt;文件搜索&lt;/h1&gt;
&lt;p&gt;find / -name file1 从 ‘/’ 开始进入根文件系统搜索文件和目录 &lt;br /&gt;
find / -user user1 搜索属于用户 ‘user1’ 的文件和目录 &lt;br /&gt;
find /home/user1 -name *.bin 在目录 ‘/ home/user1’ 中搜索带有’.bin’ 结尾的文件 &lt;br /&gt;
find /usr/bin -type f -atime +100 搜索在过去100天内未被使用过的执行文件 &lt;br /&gt;
find /usr/bin -type f -mtime -10 搜索在10天内被创建或者修改过的文件 &lt;br /&gt;
find / -name *.rpm -exec chmod 755 ‘{}’ \; 搜索以 ‘.rpm’ 结尾的文件并定义其权限 &lt;br /&gt;
find / -xdev -name *.rpm 搜索以 ‘.rpm’ 结尾的文件，忽略光驱、捷盘等可移动设备 &lt;br /&gt;
locate *.ps 寻找以 ‘.ps’ 结尾的文件 - 先运行 ‘updatedb’ 命令 &lt;br /&gt;
whereis halt 显示一个二进制文件、源码或man的位置 &lt;br /&gt;
which halt 显示一个二进制文件或可执行文件的完整路径&lt;/p&gt;

&lt;h1 id=&quot;挂载一个文件系统&quot;&gt;挂载一个文件系统&lt;/h1&gt;
&lt;p&gt;mount /dev/hda2 /mnt/hda2 挂载一个叫做hda2的盘 - 确定目录 ‘/ mnt/hda2’ 已经存在 &lt;br /&gt;
umount /dev/hda2 卸载一个叫做hda2的盘 - 先从挂载点 ‘/ mnt/hda2’ 退出 &lt;br /&gt;
fuser -km /mnt/hda2 当设备繁忙时强制卸载 &lt;br /&gt;
umount -n /mnt/hda2 运行卸载操作而不写入 /etc/mtab 文件- 当文件为只读或当磁盘写满时非常有用 &lt;br /&gt;
mount /dev/fd0 /mnt/floppy 挂载一个软盘 &lt;br /&gt;
mount /dev/cdrom /mnt/cdrom 挂载一个cdrom或dvdrom &lt;br /&gt;
mount /dev/hdc /mnt/cdrecorder 挂载一个cdrw或dvdrom &lt;br /&gt;
mount /dev/hdb /mnt/cdrecorder 挂载一个cdrw或dvdrom&lt;br /&gt;
mount -o loop file.iso /mnt/cdrom 挂载一个文件或ISO镜像文件 &lt;br /&gt;
mount -t vfat /dev/hda5 /mnt/hda5 挂载一个Windows FAT32文件系统 &lt;br /&gt;
mount /dev/sda1 /mnt/usbdisk 挂载一个usb 捷盘或闪存设备 &lt;br /&gt;
mount -t smbfs -o username=user,password=pass //WinClient/share /mnt/share 挂载一个windows网络共享&lt;/p&gt;

&lt;h1 id=&quot;磁盘空间&quot;&gt;磁盘空间&lt;/h1&gt;
&lt;p&gt;df -h 显示已经挂载的分区列表 &lt;br /&gt;
ls -lSr |more 以尺寸大小排列文件和目录 &lt;br /&gt;
du -sh dir1 估算目录 ‘dir1’ 已经使用的磁盘空间’ &lt;br /&gt;
du -sk * | sort -rn 以容量大小为依据依次显示文件和目录的大小 &lt;br /&gt;
rpm -q -a –qf ‘%10{SIZE}t%{NAME}n’ | sort -k1,1n 以大小为依据依次显示已安装的rpm包所使用的空间 (fedora, redhat类系统) &lt;br /&gt;
dpkg-query -W -f=’${Installed-Size;10}t${Package}n’ | sort -k1,1n 以大小为依据显示已安装的deb包所使用的空间 (ubuntu, debian类系统)&lt;/p&gt;

&lt;h1 id=&quot;用户和群组&quot;&gt;用户和群组&lt;/h1&gt;
&lt;p&gt;groupadd group_name 创建一个新用户组 &lt;br /&gt;
groupdel group_name 删除一个用户组 &lt;br /&gt;
groupmod -n new_group_name old_group_name 重命名一个用户组 &lt;br /&gt;
useradd -c “Name Surname “ -g admin -d /home/user1 -s /bin/bash user1 创建一个属于 “admin” 用户组的用户 &lt;br /&gt;
useradd user1 创建一个新用户 &lt;br /&gt;
userdel -r user1 删除一个用户 ( ‘-r’ 排除主目录) &lt;br /&gt;
usermod -c “User FTP” -g system -d /ftp/user1 -s /bin/nologin user1 修改用户属性 &lt;br /&gt;
passwd 修改口令 &lt;br /&gt;
passwd user1 修改一个用户的口令 (只允许root执行) &lt;br /&gt;
chage -E 2005-12-31 user1 设置用户口令的失效期限 &lt;br /&gt;
pwck 检查 ‘/etc/passwd’ 的文件格式和语法修正以及存在的用户 &lt;br /&gt;
grpck 检查 ‘/etc/passwd’ 的文件格式和语法修正以及存在的群组 &lt;br /&gt;
newgrp group_name 登陆进一个新的群组以改变新创建文件的预设群组&lt;/p&gt;

&lt;h1 id=&quot;文件的权限---使用--设置权限使用---用于取消&quot;&gt;文件的权限 - 使用 “+” 设置权限，使用 “-“ 用于取消&lt;/h1&gt;
&lt;p&gt;ls -lh 显示权限 &lt;br /&gt;
ls /tmp | pr -T5 -W$COLUMNS 将终端划分成5栏显示 &lt;br /&gt;
chmod ugo+rwx directory1 设置目录的所有人(u)、群组(g)以及其他人(o)以读（r ）、写(w)和执行(x)的权限 &lt;br /&gt;
chmod go-rwx directory1 删除群组(g)与其他人(o)对目录的读写执行权限&lt;br /&gt;
chown user1 file1 改变一个文件的所有人属性 &lt;br /&gt;
chown -R user1 directory1 改变一个目录的所有人属性并同时改变改目录下所有文件的属性 &lt;br /&gt;
chgrp group1 file1 改变文件的群组 &lt;br /&gt;
chown user1:group1 file1 改变一个文件的所有人和群组属性 &lt;br /&gt;
find / -perm -u+s 罗列一个系统中所有使用了SUID控制的文件 &lt;br /&gt;
chmod u+s /bin/file1 设置一个二进制文件的 SUID 位 - 运行该文件的用户也被赋予和所有者同样的权限 &lt;br /&gt;
chmod u-s /bin/file1 禁用一个二进制文件的 SUID位 &lt;br /&gt;
chmod g+s /home/public 设置一个目录的SGID 位 - 类似SUID ，不过这是针对目录的 &lt;br /&gt;
chmod g-s /home/public 禁用一个目录的 SGID 位 &lt;br /&gt;
chmod o+t /home/public 设置一个文件的 STIKY 位 - 只允许合法所有人删除文件 &lt;br /&gt;
chmod o-t /home/public 禁用一个目录的 STIKY 位&lt;/p&gt;

&lt;h1 id=&quot;文件的特殊属性---使用--设置权限使用---用于取消&quot;&gt;文件的特殊属性 - 使用 “+” 设置权限，使用 “-“ 用于取消&lt;/h1&gt;
&lt;p&gt;chattr +a file1 只允许以追加方式读写文件 &lt;br /&gt;
chattr +c file1 允许这个文件能被内核自动压缩/解压 &lt;br /&gt;
chattr +d file1 在进行文件系统备份时，dump程序将忽略这个文件 &lt;br /&gt;
chattr +i file1 设置成不可变的文件，不能被删除、修改、重命名或者链接 &lt;br /&gt;
chattr +s file1 允许一个文件被安全地删除 &lt;br /&gt;
chattr +S file1 一旦应用程序对这个文件执行了写操作，使系统立刻把修改的结果写到磁盘 &lt;br /&gt;
chattr +u file1 若文件被删除，系统会允许你在以后恢复这个被删除的文件 &lt;br /&gt;
lsattr 显示特殊的属性&lt;/p&gt;

&lt;h1 id=&quot;打包和压缩文件&quot;&gt;打包和压缩文件&lt;/h1&gt;
&lt;p&gt;gzip file1 压缩一个叫做 ‘file1’的文件 &lt;br /&gt;
gzip -9 file1 最大程度压缩 &lt;br /&gt;
tar -cvf archive.tar file1 创建一个非压缩的 tarball &lt;br /&gt;
tar -cvf archive.tar file1 file2 dir1 创建一个包含了 ‘file1’, ‘file2’ 以及 ‘dir1’的档案文件 &lt;br /&gt;
tar -tf archive.tar 显示一个包中的内容 &lt;br /&gt;
tar -xvf archive.tar 释放一个包 &lt;br /&gt;
tar -xvf archive.tar -C /tmp 将压缩包释放到 /tmp目录下 &lt;br /&gt;
tar -cvfj archive.tar.bz2 dir1 创建一个bzip2格式的压缩包 &lt;br /&gt;
tar -jxvf archive.tar.bz2 解压一个bzip2格式的压缩包 &lt;br /&gt;
tar -cvfz archive.tar.gz dir1 创建一个gzip格式的压缩包 &lt;br /&gt;
tar -zxvf archive.tar.gz 解压一个gzip格式的压缩包 &lt;br /&gt;
zip file1.zip file1 创建一个zip格式的压缩包 &lt;br /&gt;
zip -r file1.zip file1 file2 dir1 将几个文件和目录同时压缩成一个zip格式的压缩包 &lt;br /&gt;
unzip file1.zip 解压一个zip格式压缩包&lt;/p&gt;

&lt;h1 id=&quot;rpm-包---fedora-redhat及类似系统&quot;&gt;RPM 包 - （Fedora, Redhat及类似系统）&lt;/h1&gt;
&lt;p&gt;rpm -ivh package.rpm 安装一个rpm包 &lt;br /&gt;
rpm -ivh –nodeeps package.rpm 安装一个rpm包而忽略依赖关系警告 &lt;br /&gt;
rpm -U package.rpm 更新一个rpm包但不改变其配置文件 &lt;br /&gt;
rpm -F package.rpm 更新一个确定已经安装的rpm包 &lt;br /&gt;
rpm -e package_name.rpm 删除一个rpm包 &lt;br /&gt;
rpm -qa 显示系统中所有已经安装的rpm包 &lt;br /&gt;
rpm -qa | grep httpd 显示所有名称中包含 “httpd” 字样的rpm包 &lt;br /&gt;
rpm -qi package_name 获取一个已安装包的特殊信息 &lt;br /&gt;
rpm -qg “System Environment/Daemons” 显示一个组件的rpm包 &lt;br /&gt;
rpm -ql package_name 显示一个已经安装的rpm包提供的文件列表 &lt;br /&gt;
rpm -qc package_name 显示一个已经安装的rpm包提供的配置文件列表 &lt;br /&gt;
rpm -q package_name –whatrequires 显示与一个rpm包存在依赖关系的列表 &lt;br /&gt;
rpm -q package_name –whatprovides 显示一个rpm包所占的体积 &lt;br /&gt;
rpm -q package_name –scripts 显示在安装/删除期间所执行的脚本l &lt;br /&gt;
rpm -q package_name –changelog 显示一个rpm包的修改历史 &lt;br /&gt;
rpm -qf /etc/httpd/conf/httpd.conf 确认所给的文件由哪个rpm包所提供 &lt;br /&gt;
rpm -qp package.rpm -l 显示由一个尚未安装的rpm包提供的文件列表 &lt;br /&gt;
rpm –import /media/cdrom/RPM-GPG-KEY 导入公钥数字证书 &lt;br /&gt;
rpm –checksig package.rpm 确认一个rpm包的完整性 &lt;br /&gt;
rpm -qa gpg-pubkey 确认已安装的所有rpm包的完整性 &lt;br /&gt;
rpm -V package_name 检查文件尺寸、 许可、类型、所有者、群组、MD5检查以及最后修改时间 &lt;br /&gt;
rpm -Va 检查系统中所有已安装的rpm包- 小心使用 &lt;br /&gt;
rpm -Vp package.rpm 确认一个rpm包还未安装 &lt;br /&gt;
rpm -ivh /usr/src/redhat/RPMS/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arch&lt;/code&gt;/package.rpm 从一个rpm源码安装一个构建好的包 &lt;br /&gt;
rpmbuild –rebuild package_name.src.rpm 从一个rpm源码构建一个 rpm 包&lt;/p&gt;

&lt;h1 id=&quot;yum-软件包升级器---fedora-redhat及类似系统&quot;&gt;YUM 软件包升级器 - （Fedora, RedHat及类似系统）&lt;/h1&gt;
&lt;p&gt;yum install package_name 下载并安装一个rpm包 &lt;br /&gt;
yum localinstall package_name.rpm 将安装一个rpm包，使用你自己的软件仓库为你解决所有依赖关系 &lt;br /&gt;
yum update package_name.rpm 更新当前系统中所有安装的rpm包 &lt;br /&gt;
yum update package_name 更新一个rpm包 &lt;br /&gt;
yum remove package_name 删除一个rpm包 &lt;br /&gt;
yum list 列出当前系统中安装的所有包 &lt;br /&gt;
yum search package_name 在rpm仓库中搜寻软件包 &lt;br /&gt;
yum clean packages 清理rpm缓存删除下载的包 &lt;br /&gt;
yum clean headers 删除所有头文件 &lt;br /&gt;
yum clean all 删除所有缓存的包和头文件&lt;/p&gt;

&lt;h1 id=&quot;查看文件内容&quot;&gt;查看文件内容&lt;/h1&gt;
&lt;p&gt;cat file1 从第一个字节开始正向查看文件的内容 &lt;br /&gt;
tac file1 从最后一行开始反向查看一个文件的内容 &lt;br /&gt;
more file1 查看一个长文件的内容 &lt;br /&gt;
less file1 类似于 ‘more’ 命令，但是它允许在文件中和正向操作一样的反向操作 &lt;br /&gt;
head -2 file1 查看一个文件的前两行 &lt;br /&gt;
tail -2 file1 查看一个文件的最后两行 &lt;br /&gt;
tail -f /var/log/messages 实时查看被添加到一个文件中的内容&lt;/p&gt;

&lt;h1 id=&quot;文本处理&quot;&gt;文本处理&lt;/h1&gt;
&lt;p&gt;cat file1 file2 … | command &amp;lt;&amp;gt; file1_in.txt_or_file1_out.txt general syntax for text manipulation using PIPE, STDIN and STDOUT &lt;br /&gt;
cat file1 | command( sed, grep, awk, grep, etc…) &amp;gt; result.txt 合并一个文件的详细说明文本，并将简介写入一个新文件中 &lt;br /&gt;
cat file1 | command( sed, grep, awk, grep, etc…) » result.txt 合并一个文件的详细说明文本，并将简介写入一个已有的文件中 &lt;br /&gt;
grep Aug /var/log/messages 在文件 ‘/var/log/messages’中查找关键词”Aug” &lt;br /&gt;
grep ^Aug /var/log/messages 在文件 ‘/var/log/messages’中查找以”Aug”开始的词汇 &lt;br /&gt;
grep [0-9] /var/log/messages 选择 ‘/var/log/messages’ 文件中所有包含数字的行 &lt;br /&gt;
grep Aug -R /var/log/* 在目录 ‘/var/log’ 及随后的目录中搜索字符串”Aug” &lt;br /&gt;
sed ‘s/stringa1/stringa2/g’ example.txt 将example.txt文件中的 “string1” 替换成 “string2” &lt;br /&gt;
sed ‘/^$/d’ example.txt 从example.txt文件中删除所有空白行 &lt;br /&gt;
sed ‘/ &lt;em&gt;#/d; /^$/d’ example.txt 从example.txt文件中删除所有注释和空白行 &lt;br /&gt;
echo ‘esempio’ | tr ‘[:lower:]’ ‘[:upper:]’ 合并上下单元格内容 &lt;br /&gt;
sed -e ‘1d’ result.txt 从文件example.txt 中排除第一行 &lt;br /&gt;
sed -n ‘/stringa1/p’ 查看只包含词汇 “string1”的行 &lt;br /&gt;
sed -e ‘s/ *$//’ example.txt 删除每一行最后的空白字符 &lt;br /&gt;
sed -e ‘s/stringa1//g’ example.txt 从文档中只删除词汇 “string1” 并保留剩余全部 &lt;br /&gt;
sed -n ‘1,5p;5q’ example.txt 查看从第一行到第5行内容 &lt;br /&gt;
sed -n ‘5p;5q’ example.txt 查看第5行 &lt;br /&gt;
sed -e ‘s/00&lt;/em&gt;/0/g’ example.txt 用单个零替换多个零 &lt;br /&gt;
cat -n file1 标示文件的行数 &lt;br /&gt;
cat example.txt | awk ‘NR%2==1’ 删除example.txt文件中的所有偶数行 &lt;br /&gt;
echo a b c | awk ‘{print $1}’ 查看一行第一栏 &lt;br /&gt;
echo a b c | awk ‘{print $1,$3}’ 查看一行的第一和第三栏 &lt;br /&gt;
paste file1 file2 合并两个文件或两栏的内容 &lt;br /&gt;
paste -d ‘+’ file1 file2 合并两个文件或两栏的内容，中间用”+”区分 &lt;br /&gt;
sort file1 file2 排序两个文件的内容 &lt;br /&gt;
sort file1 file2 | uniq 取出两个文件的并集(重复的行只保留一份) &lt;br /&gt;
sort file1 file2 | uniq -u 删除交集，留下其他的行 &lt;br /&gt;
sort file1 file2 | uniq -d 取出两个文件的交集(只留下同时存在于两个文件中的文件) &lt;br /&gt;
comm -1 file1 file2 比较两个文件的内容只删除 ‘file1’ 所包含的内容 &lt;br /&gt;
comm -2 file1 file2 比较两个文件的内容只删除 ‘file2’ 所包含的内容 &lt;br /&gt;
comm -3 file1 file2 比较两个文件的内容只删除两个文件共有的部分&lt;/p&gt;

&lt;h1 id=&quot;字符设置和文件格式转换&quot;&gt;字符设置和文件格式转换&lt;/h1&gt;
&lt;p&gt;dos2unix filedos.txt fileunix.txt 将一个文本文件的格式从MSDOS转换成UNIX &lt;br /&gt;
unix2dos fileunix.txt filedos.txt 将一个文本文件的格式从UNIX转换成MSDOS &lt;br /&gt;
recode ..HTML &amp;lt; page.txt &amp;gt; page.html 将一个文本文件转换成html &lt;br /&gt;
recode -l | more 显示所有允许的转换格式&lt;/p&gt;

&lt;h1 id=&quot;文件系统分析&quot;&gt;文件系统分析&lt;/h1&gt;
&lt;p&gt;badblocks -v /dev/hda1 检查磁盘hda1上的坏磁块 &lt;br /&gt;
fsck /dev/hda1 修复/检查hda1磁盘上linux文件系统的完整性 &lt;br /&gt;
fsck.ext2 /dev/hda1 修复/检查hda1磁盘上ext2文件系统的完整性 &lt;br /&gt;
e2fsck /dev/hda1 修复/检查hda1磁盘上ext2文件系统的完整性 &lt;br /&gt;
e2fsck -j /dev/hda1 修复/检查hda1磁盘上ext3文件系统的完整性 &lt;br /&gt;
fsck.ext3 /dev/hda1 修复/检查hda1磁盘上ext3文件系统的完整性 &lt;br /&gt;
fsck.vfat /dev/hda1 修复/检查hda1磁盘上fat文件系统的完整性 &lt;br /&gt;
fsck.msdos /dev/hda1 修复/检查hda1磁盘上dos文件系统的完整性 &lt;br /&gt;
dosfsck /dev/hda1 修复/检查hda1磁盘上dos文件系统的完整性&lt;/p&gt;

&lt;h1 id=&quot;初始化一个文件系统&quot;&gt;初始化一个文件系统&lt;/h1&gt;
&lt;p&gt;mkfs /dev/hda1 在hda1分区创建一个文件系统 &lt;br /&gt;
mke2fs /dev/hda1 在hda1分区创建一个linux ext2的文件系统 &lt;br /&gt;
mke2fs -j /dev/hda1 在hda1分区创建一个linux ext3(日志型)的文件系统 &lt;br /&gt;
mkfs -t vfat 32 -F /dev/hda1 创建一个 FAT32 文件系统 &lt;br /&gt;
fdformat -n /dev/fd0 格式化一个软盘 &lt;br /&gt;
mkswap /dev/hda3 创建一个swap文件系统&lt;/p&gt;

&lt;h1 id=&quot;swap文件系统&quot;&gt;SWAP文件系统&lt;/h1&gt;
&lt;p&gt;mkswap /dev/hda3 创建一个swap文件系统 &lt;br /&gt;
swapon /dev/hda3 启用一个新的swap文件系统 &lt;br /&gt;
swapon /dev/hda2 /dev/hdb3 启用两个swap分区&lt;/p&gt;

&lt;h1 id=&quot;备份&quot;&gt;备份&lt;/h1&gt;
&lt;p&gt;dump -0aj -f /tmp/home0.bak /home 制作一个 ‘/home’ 目录的完整备份 &lt;br /&gt;
dump -1aj -f /tmp/home0.bak /home 制作一个 ‘/home’ 目录的交互式备份 &lt;br /&gt;
restore -if /tmp/home0.bak 还原一个交互式备份 &lt;br /&gt;
rsync -rogpav –delete /home /tmp 同步两边的目录 &lt;br /&gt;
rsync -rogpav -e ssh –delete /home ip_address:/tmp 通过SSH通道rsync &lt;br /&gt;
rsync -az -e ssh –delete ip_addr:/home/public /home/local 通过ssh和压缩将一个远程目录同步到本地目录 &lt;br /&gt;
rsync -az -e ssh –delete /home/local ip_addr:/home/public 通过ssh和压缩将本地目录同步到远程目录 &lt;br /&gt;
dd bs=1M if=/dev/hda | gzip | ssh user@ip_addr ‘dd of=hda.gz’ 通过ssh在远程主机上执行一次备份本地磁盘的操作 &lt;br /&gt;
dd if=/dev/sda of=/tmp/file1 备份磁盘内容到一个文件 &lt;br /&gt;
tar -Puf backup.tar /home/user 执行一次对 ‘/home/user’ 目录的交互式备份操作 &lt;br /&gt;
( cd /tmp/local/ &amp;amp;&amp;amp; tar c . ) | ssh -C user@ip_addr ‘cd /home/share/ &amp;amp;&amp;amp; tar x -p’ 通过ssh在远程目录中复制一个目录内容 &lt;br /&gt;
( tar c /home ) | ssh -C user@ip_addr ‘cd /home/backup-home &amp;amp;&amp;amp; tar x -p’ 通过ssh在远程目录中复制一个本地目录 &lt;br /&gt;
tar cf - . | (cd /tmp/backup ; tar xf - ) 本地将一个目录复制到另一个地方，保留原有权限及链接 &lt;br /&gt;
find /home/user1 -name ‘*.txt’ | xargs cp -av –target-directory=/home/backup/ –parents 从一个目录查找并复制所有以 ‘.txt’ 结尾的文件到另一个目录 &lt;br /&gt;
find /var/log -name ‘*.log’ | tar cv –files-from=- | bzip2 &amp;gt; log.tar.bz2 查找所有以 ‘.log’ 结尾的文件并做成一个bzip包 &lt;br /&gt;
dd if=/dev/hda of=/dev/fd0 bs=512 count=1 做一个将 MBR (Master Boot Record)内容复制到软盘的动作 &lt;br /&gt;
dd if=/dev/fd0 of=/dev/hda bs=512 count=1 从已经保存到软盘的备份中恢复MBR内容&lt;/p&gt;

&lt;h1 id=&quot;网络---以太网和wifi无线&quot;&gt;网络 - （以太网和WIFI无线）&lt;/h1&gt;
&lt;p&gt;ifconfig eth0 显示一个以太网卡的配置 &lt;br /&gt;
ifup eth0 启用一个 ‘eth0’ 网络设备 &lt;br /&gt;
ifdown eth0 禁用一个 ‘eth0’ 网络设备 &lt;br /&gt;
ifconfig eth0 192.168.1.1 netmask 255.255.255.0 控制IP地址 &lt;br /&gt;
ifconfig eth0 promisc 设置 ‘eth0’ 成混杂模式以嗅探数据包 (sniffing) &lt;br /&gt;
dhclient eth0 以dhcp模式启用 ‘eth0’ &lt;br /&gt;
route -n show routing table &lt;br /&gt;
route add -net 0/0 gw IP_Gateway configura default gateway &lt;br /&gt;
route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1 configure static route to reach network ‘192.168.0.0/16’ &lt;br /&gt;
route del 0/0 gw IP_gateway remove static route &lt;br /&gt;
echo “1” &amp;gt; /proc/sys/net/ipv4/ip_forward activate ip routing &lt;br /&gt;
hostname show hostname of system &lt;br /&gt;
host www.example.com lookup hostname to resolve name to ip address and viceversa&lt;br /&gt;
nslookup www.example.com lookup hostname to resolve name to ip address and viceversa&lt;br /&gt;
ip link show show link status of all interfaces &lt;br /&gt;
mii-tool eth0 show link status of ‘eth0’ &lt;br /&gt;
ethtool eth0 show statistics of network card ‘eth0’ &lt;br /&gt;
netstat -tup show all active network connections and their PID &lt;br /&gt;
netstat -tupl show all network services listening on the system and their PID &lt;br /&gt;
tcpdump tcp port 80 show all HTTP traffic &lt;br /&gt;
iwlist scan show wireless networks &lt;br /&gt;
iwconfig eth1 show configuration of a wireless network card &lt;br /&gt;
hostname show hostname &lt;br /&gt;
host www.example.com lookup hostname to resolve name to ip address and viceversa&lt;br /&gt;
nslookup www.example.com lookup hostname to resolve name to ip address and viceversa &lt;br /&gt;
whois www.example.com lookup on Whois database&lt;/p&gt;

</description>
        <pubDate>Thu, 11 Jul 2019 16:08:00 +0000</pubDate>
        <link>https://ljw718.github.io//2019/07/11/About-Linux-CMD/</link>
        <guid isPermaLink="true">https://ljw718.github.io//2019/07/11/About-Linux-CMD/</guid>
        
        <category>Linux常用shell命令</category>
        
        
        <category>Linux</category>
        
      </item>
    
      <item>
        <title>基于Linux下的C函数使用</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#1gb2312与utf-8互转&quot; id=&quot;markdown-toc-1gb2312与utf-8互转&quot;&gt;1、GB2312与UTF-8互转&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#2strtok函数&quot; id=&quot;markdown-toc-2strtok函数&quot;&gt;2、strtok()函数&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;本篇博客是介绍C语言中一些常用、易用错的函数的使用方法,每个函数使用都以实例展示,并且都是在项目中实际用到过,持续更新…&lt;/p&gt;

&lt;h1 id=&quot;1gb2312与utf-8互转&quot;&gt;1、GB2312与UTF-8互转&lt;/h1&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#include &amp;lt;iconv.h&amp;gt;
int code_convert(char *from_charset,char *to_charset,char *inbuf,int inlen,char *outbuf,int outlen)
{
​	iconv_t cd = NULL;
​	//int rc;
​	char **pin = &amp;amp;inbuf;
​	char **pout = &amp;amp;outbuf;
​	cd = iconv_open(to_charset,from_charset);
​	if(cd == (void *)-1)
​	{
​		return FAIL;
​	}
​	size_t n = iconv(cd,pin,&amp;amp;inlen,pout,&amp;amp;outlen);  //iconv返回转换期间不可转换字符的数量
​	if(n &amp;lt; 0)
​	{
​		return FAIL;
​	}
​	iconv_close(cd);
	return SUC;
}

//UNICODE码转为GB2312码
int u2g(char *inbuf,int inlen,char *outbuf,int outlen)
{
​	return code_convert(&quot;utf-8&quot;,&quot;gb2312&quot;,inbuf,inlen,outbuf,outlen);
}

//GB2312码转为UNICODE码
int g2u(char *inbuf,size_t inlen,char *outbuf,size_t outlen)
{
	return code_convert(&quot;gb2312&quot;,&quot;utf-8&quot;,inbuf,inlen,outbuf,outlen);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;2strtok函数&quot;&gt;2、strtok()函数&lt;/h1&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;string.h&amp;gt;
int main(void)
{
​    char buf[]=&quot;hello@boy@this@is@heima&quot;;
​    char*temp = strtok(buf,&quot;@&quot;);
​    while(temp)
​    {
​        printf(&quot;%s &quot;,temp);
​        temp = strtok(NULL,&quot;@&quot;);
​    }
​    return 0;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Tue, 25 Jun 2019 14:58:01 +0000</pubDate>
        <link>https://ljw718.github.io//2019/06/25/About-Linux-C/</link>
        <guid isPermaLink="true">https://ljw718.github.io//2019/06/25/About-Linux-C/</guid>
        
        <category>C函数</category>
        
        
        <category>Linux</category>
        
      </item>
    
      <item>
        <title>Jekyll安装步骤&amp;目录结构</title>
        <description>&lt;ul id=&quot;markdown-toc&quot;&gt;
  &lt;li&gt;&lt;a href=&quot;#一背景&quot; id=&quot;markdown-toc-一背景&quot;&gt;一、背景&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#二什么是jekyll&quot; id=&quot;markdown-toc-二什么是jekyll&quot;&gt;二、什么是jekyll？&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#三jekyll安装&quot; id=&quot;markdown-toc-三jekyll安装&quot;&gt;三、jekyll安装&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#1winrdos安装&quot; id=&quot;markdown-toc-1winrdos安装&quot;&gt;1、(win+R)DOS安装&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#2shell命令安装&quot; id=&quot;markdown-toc-2shell命令安装&quot;&gt;2、Shell命令安装&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#四jekyll目录结构&quot; id=&quot;markdown-toc-四jekyll目录结构&quot;&gt;四、jekyll目录结构&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#五jekyll安装常见问题&quot; id=&quot;markdown-toc-五jekyll安装常见问题&quot;&gt;五、jekyll安装常见问题&lt;/a&gt;    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#gem证书错误&quot; id=&quot;markdown-toc-gem证书错误&quot;&gt;Gem 证书错误&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;一背景&quot;&gt;一、背景&lt;/h2&gt;
&lt;p&gt;由于最近换了新电脑，之前的Jekyll环境用不了了，但是之前创建的仓库&lt;a href=&quot;http://ljw718.github.io&quot;&gt;https://LJW718.github.io&lt;/a&gt; 依然是可以访问的，所以需要在新电脑上重新安装。&lt;/p&gt;

&lt;h2 id=&quot;二什么是jekyll&quot;&gt;二、什么是jekyll？&lt;/h2&gt;

&lt;p&gt;首先解释下什么是jekyll，jekyll相当于一个编译工具，安装好jekyll后，你可以通过jekyll创建一个网站模板，创建好之后，我们就可以通过http://127.0.0.1:4000/ 访问刚刚创建的网站了（具体jekyll用法后面再介绍），我们可以实时修改刚刚创建的模板里面的内容，并可以实时通过本地url预览改动后的效果。我们把这个博客推送到上一步创建的代码仓库里，再通过https://ljw718.github.io/ 就可以访问到博客里面的内容了。有了Jekyll，我们不用每次改动一点点就把代码推送到仓库中进行预览，而是本地就可以预览。GitHub支持jekyll，hexo等语法解析。
那么如何安装jekyll呢？我这边暂只讲解windows下的安装步骤。&lt;/p&gt;

&lt;h2 id=&quot;三jekyll安装&quot;&gt;三、jekyll安装&lt;/h2&gt;

&lt;p&gt;首先进入官网点击下载安装&lt;a href=&quot;https://rubyinstaller.org/&quot;&gt;Ruby installer&lt;/a&gt;;  或者用阿里云盘下载：&lt;a href=&quot;https://www.aliyundrive.com/s/C6ULdQDbome&quot;&gt;Ruby2.6.1.1&lt;/a&gt;
点击下载&lt;a href=&quot;https://rubygems.org/pages/download&quot;&gt;RubyGems&lt;/a&gt;, 或者用阿里云盘下载：&lt;a href=&quot;https://www.aliyundrive.com/s/KkiH9ftS3ZY&quot;&gt;[RubyGems3.0.2]&lt;/a&gt; , 不建议下载最新的版本，可能存在兼容性问题， 用我的这两个链接下载即可，亲测有效。下载完成后解压至你想放的位置,&lt;/p&gt;

&lt;p&gt;例如我放到E:\rubygems-3.0.2。&lt;/p&gt;

&lt;h3 id=&quot;1winrdos安装&quot;&gt;1、(win+R)DOS安装&lt;/h3&gt;
&lt;p&gt;打开命令行执行,进入到解压包的位置：cd E:\rubygems-3.0.2 &lt;br /&gt;
E:&lt;br /&gt;
ruby setup.rb&lt;br /&gt;
在命令行执行gem install jekyll；&lt;br /&gt;
安装完成，我们可以用jekyll命令创建一个博客模板,打开命令行执行：  &lt;br /&gt;
cd d:  &lt;br /&gt;
d:  &lt;br /&gt;
jekyll new testblog&lt;br /&gt;
cd testblog&lt;br /&gt;
jekyll server&lt;/p&gt;

&lt;h3 id=&quot;2shell命令安装&quot;&gt;2、Shell命令安装&lt;/h3&gt;
&lt;p&gt;熟悉Linux的朋友应该不陌生，我们先安装一个可以在windows下敲shell命令的工具，我们拿Git-bash为例(Git命令行输入工具),兼容部分shell命令,然后在git-bash终端完成jekyll安装以及启动。&lt;br /&gt;
打开命令行执行,进入到解压包的位置：cd E:\rubygems-3.0.2 &lt;br /&gt;
ruby setup.rb&lt;br /&gt;
在命令行执行gem install jekyll；&lt;br /&gt;
安装完成，我们可以用jekyll命令创建一个博客模板,打开命令行执行：  &lt;br /&gt;
cd d:    &lt;br /&gt;
jekyll new testblog&lt;br /&gt;
cd testblog&lt;br /&gt;
jekyll server&lt;br /&gt;
操作和DOS命令基本一致，个人习惯使用Linux命令。&lt;/p&gt;

&lt;p&gt;在浏览器输入http://127.0.0.1:4000/ 即可浏览刚刚创建的blog&lt;br /&gt;
到此jekyll 就安装完成了。&lt;/p&gt;

&lt;h2 id=&quot;四jekyll目录结构&quot;&gt;四、jekyll目录结构&lt;/h2&gt;
&lt;p&gt;jekyll目录结构主要包含如下目录：&lt;br /&gt;
_posts 博客内容&lt;br /&gt;
_pages 其他需要生成的网页，如About页&lt;br /&gt;
_layouts 网页排版模板&lt;br /&gt;
_includes 被模板包含的HTML片段，可在_config.yml中修改位置&lt;br /&gt;
assets 辅助资源 css布局 js脚本 图片等&lt;br /&gt;
_data 动态数据&lt;br /&gt;
_sites 最终生成的静态网页&lt;br /&gt;
_config.yml 网站的一些配置信息&lt;br /&gt;
index.html 网站的入口&lt;/p&gt;

&lt;h2 id=&quot;五jekyll安装常见问题&quot;&gt;五、jekyll安装常见问题&lt;/h2&gt;

&lt;h3 id=&quot;gem证书错误&quot;&gt;Gem 证书错误&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/styles/images/Other/图片 2.png&quot; alt=&quot;p1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;1.先查看证书默认位置,系统,安装不一样可能导致证书查找位置不同&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ruby -e &quot;require &apos;openssl&apos;; puts OpenSSL::X509::DEFAULT_CERT_FILE&quot;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/Other/图片 4.png&quot; alt=&quot;p2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;比如检查出地址是 D:/Ruby30-x64/ssl/cert.pem , 备份一下cert_bak.pem&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/Other/图片 6.png&quot; alt=&quot;p3&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;curl -o  D:\Ruby30-x64\ssl\aaa.pem  https://curl.haxx.se/ca/cacert.pem&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/Other/图片 11.png&quot; alt=&quot;p4&quot; /&gt;&lt;/p&gt;

&lt;p&gt;一次不行， 多试几次。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/Other/图片 8.png&quot; alt=&quot;p5&quot; /&gt;&lt;/p&gt;

&lt;p&gt;点击aaa中的html链接， 下载证书&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/Other/图片 7.png&quot; alt=&quot;p6&quot; /&gt;&lt;/p&gt;

&lt;p&gt;将证书名字改成cert.pem,证书配置完成&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gem source -a https://rubygems.org/&lt;/code&gt;  （修改Ruby的gem源，默认的源， 之前删除了）&lt;/p&gt;

&lt;p&gt;安装jekyll:    &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gem install jekyll&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/Other/图片 9.png&quot; alt=&quot;p7&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/styles/images/Other/图片 5.png&quot; alt=&quot;p8&quot; /&gt;&lt;/p&gt;

</description>
        <pubDate>Sun, 23 Jun 2019 10:01:01 +0000</pubDate>
        <link>https://ljw718.github.io//2019/06/23/jekyll-install/</link>
        <guid isPermaLink="true">https://ljw718.github.io//2019/06/23/jekyll-install/</guid>
        
        <category>jekyll</category>
        
        
        <category>jekyll</category>
        
      </item>
    
  </channel>
</rss>
