3.scala容器
3.scala容器
a:focus {
outline: thin dotted #333;
outline: 5px auto -webkit-focus-ring-color;
outline-offset: -2px;
}
a:hover,
a:active {
outline: 0;
}
a {
color: #0088cc;
text-decoration: none;
}
a:hover {
color: #005580;
text-decoration: underline;
}
p {
margin: 0 0 1.1em;
}
small {
font-size: 85%;
}
strong {
font-weight: bold;
}
em {
font-style: italic;
}
cite {
font-style: normal;
}
h1.story_title {
margin: 0.7em 0;
}
.story_tags {
margin: 0 0 1.2em;
}
h1,
h2,
h3,
h4,
h5,
h6 {
margin: 0.5em 0;
margin: 1.0em 0 .6em 0;
font-family: inherit;
font-weight: 500;
line-height: 20px;
color: inherit;
text-rendering: optimizelegibility;
}
h1,
h2,
h3 {
line-height: 40px;
}
h1 {
font-size: 38.5px;
}
h2 {
font-size: 31.5px;
}
h3 {
font-size: 24.5px;
}
h4 {
font-size: 17.5px;
}
h5 {
font-size: 14px;
}
h6 {
font-size: 11.9px;
}
ul,
ol {
padding: 0;
margin: 0 0 10px 35px;
}
ul ul,
ul ol,
ol ol,
ol ul {
margin-bottom: 0;
}
dl {
margin-bottom: 20px;
}
dt,
dd {
line-height: 20px;
}
dt {
font-weight: bold;
}
dd {
margin-left: 10px;
}
hr {
margin: 20px 0;
border: 0;
border-top: 1px solid #eeeeee;
border-bottom: 1px solid #ffffff;
}
abbr[title],
abbr[data-original-title] {
cursor: help;
border-bottom: 1px dotted #999999;
}
blockquote {
padding: 0 0 0 15px;
margin: 0 0 20px;
border-left: 5px solid #dddddd;
}
blockquote p {
margin-bottom: 0;
font-size: 16px;
font-weight: 300;
line-height: 25px;
}
blockquote small {
display: block;
line-height: 20px;
color: #999999;
}
blockquote small:before {
content: '\2014 \00A0';
}
q:before,
q:after,
blockquote:before,
blockquote:after {
content: "";
}
address {
display: block;
margin-bottom: 20px;
font-style: normal;
line-height: 20px;
}
img {
height: auto;
max-width: 100%;
vertical-align: middle;
border: 0;
}
table {
max-width: 100%;
background-color: transparent;
border-collapse: collapse;
border-spacing: 0;
border: 1px solid rgba(34,36,38,.15);
}
.tag.label{
display: inline-block;
vertical-align: baseline;
line-height: 1;
margin: 0em 0.125em;
background-color: #e8e8e8;
border-color: #e8e8e8;
background-image: none;
padding: 0.6em 0.8em;
color: rgba(0, 0, 0, 0.6);
text-transform: none;
font-weight: bold;
border-radius: 0.2857rem;
box-sizing: border-box;
font-size: 0.7428rem;
}
.table {
width: 100%;
margin-bottom: 20px;
}
.table th,
.table td {
padding: 8px;
line-height: 20px;
text-align: left;
vertical-align: top;
border-top: 1px solid #dddddd;
}
.table th {
font-weight: bold;
}
.table thead th {
vertical-align: bottom;
}
.table caption + thead tr:first-child th,
.table caption + thead tr:first-child td,
.table colgroup + thead tr:first-child th,
.table colgroup + thead tr:first-child td,
.table thead:first-child tr:first-child th,
.table thead:first-child tr:first-child td {
border-top: 0;
}
.table tbody + tbody {
border-top: 2px solid #dddddd;
}
.table .table {
background-color: #ffffff;
}
.table-striped tbody > tr:nth-child(odd) > td,
.table-striped tbody > tr:nth-child(odd) > th {
background-color: #f9f9f9;
}
.table-celled.table tr td,.table-celled.table tr th {
border-left: 1px solid rgba(34,36,38,.1)
}
.table-celled.table tr td:first-child,.table-celled.table tr th:first-child {
border-left: none
}
.toc ul {
list-style: none;
}
p {
line-height: 1.6;
}
body>p {
margin-bottom: 1.8em;
}
body>p>img.center,
body>p>a>img.center {
display: block;
margin: 0 auto;
background-color: rgba(128,128,128,0.3);
}
body {
font-family: 'Helvetica Neue', Helvetica, Tahoma, Arial, 'Hiragino Sans GB', STHeiti, "Microsoft YaHei", "微软雅黑", 'WenQuanYi Micro Hei', STXihei, "华文细黑", Heiti, "黑体", SimSun, "宋体", Song, sans-serif;
font-size: 1.15em;
font-weight: 100;
// line-height: 1.8em;
color: #2f2f2f;
}
em.cjk_emphasis{
font-style: normal;
font-family: Georgia,"Times New Roman",Times,"楷体","AR PL UKai CN", "NSimSun","Songti SC","SimSun",serif!important;
}
body dt,
body dd {
line-height: 1.35em;
}
body code, body .xiaoshujiang_code {
// background-color: #D6DBDF;
border: 0;
border-radius: 4px;
// color: #2C3E50;
font-size: 90%;
// padding: 2px 4px;
}
code {
background-color: #D6DBDF;
border-radius: 4px;
color: #2C3E50;
padding: 2px 4px;
}
.xiaoshujiang_code ol{
margin-bottom: 0px;
}
body h1 {
line-height: 1.6;
}
body h2 {
line-hieght: 1.1;
}
body h3 {
line-height: 1.1;
}
/**
* Treeview syntax highlighting based on highlight.js
* Copyright (c) 2014-2015, Asciidocfx Team, (MIT Licensed)
* https://github.com/asciidocfx/highlight-treeview.js
*/
.language-treeview.hljs{
position: relative;
}
.hljs-folder,
.hljs-hiddenfile,
.hljs-file {
position: relative;
vertical-align: top;
display: inline-block;
height: 16px;
}
.hljs-folder:before,
.hljs-file:before,
.hljs-hiddenfile:before {
top: 0;
content: '';
width: 14px;
height: 12px;
margin-top: 0px;
margin-right: 3px;
position: relative;
display: inline-block;
background-size: 14px;
background-repeat: no-repeat;
}
.hljs-file:before,
.hljs-hiddenfile:before {
height: 14px;
margin-left: 1px;
}
.hljs-hiddenfile {
opacity: 0.6;
}
.hljs-file.photo:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c5";
}
.hljs-file.plain:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f016";
}
.hljs-file.source:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c9";
}
.hljs-file.archive:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c6";
}
.hljs-file.audio:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c7";
}
.hljs-file.video:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c8";
}
.hljs-file.pdf:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c1";
}
.hljs-file.xls:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c3";
}
.hljs-file.doc:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c2";
}
.hljs-file.ppt:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f1c4";
}
.hljs-folder:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f114";
}
.hljs-hiddenfile:before {
font: normal normal normal 14px/1 FontAwesome;
content: "\f016";
}
.hljs-tvline {
margin-left: 6px;
position: absolute;
text-indent: -99em;
padding-bottom: 8px;
vertical-align: top;
display: inline-block;
border-left-width: 1px;
border-left-style: solid;
border-left-color: rgb(94, 144, 117);
}
.hljs-folder-branch {
width: 8px;
height: 8px;
margin-top: -1px;
margin-left: 6px;
text-indent: -99em;
position: relative;
vertical-align: top;
display: inline-block;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: rgb(94, 144, 117);
}
.hljs-folder-branch.win {
width: 14px;
margin-right: 2px;
}
.hljs-folder-last-branch {
height: 7px;
width: 7px;
margin-left: 6px;
text-indent: -99em;
position: relative;
vertical-align: top;
display: inline-block;
border-bottom-width: 1px;
border-bottom-style: solid;
border-bottom-color: rgb(94, 144, 117);
border-left-width: 1px;
border-left-style: solid;
border-left-color: rgb(94, 144, 117);
}
.hljs-folder-last-branch.win {
width: 13px;
margin-right: 2px;
}
/**
* Treeview syntax highlighting based on highlight.js
*/
.mark{
border: 0;
background-color: #ddf3e7;
border-radius: 4px;
color: #29754d;
font-size: 90%;
padding: 2px 4px;
}
.line_mark{
border: 1px dashed #3A4C42;
}
code .mark, .xiaoshujiang_code .mark{
border-radius: 0px;
font-size: initial;
padding: initial;
}
a.attachment{
background-color: #ecf0f3;
border: 1px solid #bec6cb;
display: inline-block;
padding: 5px;
margin: 2px;
min-width: 250px;
}
a.attachment i.fa{
font-size: 3em;
float: left;
margin-right: 0.2em;
}
a.attachment .filename{
vertical-align: top;
text-align: left;
font-weight: bold;
}
a.attachment .filesize{
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
opacity: .6;
font-size: 80%;
white-space: nowrap;
}
.checkbox .checked{
text-decoration: line-through;
}
.flow-chart, .sequence-diagram{
text-align: center;
}
.plot, .plot-image{
text-align: center;
min-height: 200px;
min-width: 200px;
}
pre, .xiaoshujiang_pre {
line-height: initial !important;
word-wrap: break-word;
word-break: break-word;
}
.xiaoshujiang_code_container pre{
margin: 0px;
}
.xiaoshujiang_code_container.xiaoshujiang_code_chunk{
box-shadow: 0 0 0 1px #A3C293 inset,0 0 0 0 transparent;
margin: 1em 0;
padding: 1em;
}
.xiaoshujiang_code_container.xiaoshujiang_code_chunk_hide_code{
box-shadow: initial;
padding: initial;
padding-bottom: 2em;
}
.xiaoshujiang_code_container .out_put{
box-shadow: 0 0 0 1px #A3C293 inset,0 0 0 0 transparent;
margin: 1em 0;
background-color: #FCFFF5;
color: #2C662D;
padding: 1em;
}
.xiaoshujiang_code_container .out_put_error{
background-color: #FFF6F6;
color: #9F3A38;
margin: 1em 0;
box-shadow: 0 0 0 1px #E0B4B4 inset,0 0 0 0 transparent;
padding: 1em;
}
.xiaoshujiang_pre {
font-family: monospace;
white-space: pre;
}
.story_align_left, .story_align_left .story_image_container {
text-align: left;
}
.story_align_right, .story_align_right .story_image_container {
text-align: right;
}
.story_align_center, .story_align_center .story_image_container {
text-align: center;
}
.story_align_justify, .story_align_justify .story_image_container {
text-align: justify;
}
/**
* code line nums
*/
code.hljs.code_linenums, .xiaoshujiang_code.hljs.code_linenums{
position: relative;
}
.ol_linenums{
padding: 0px;
margin-left: 30px;
border-left: 1px solid #e0e0e0;
}
.li_linenum{
line-height: 20px;
margin-left: 10px;
list-style: none;
counter-increment: lines 1;
}
.li_linenum.li_list_style{
list-style: inherit;
margin-left: 5px;
}
.li_linenum:before, .li_linenum_before_span{
content: counter(lines, decimal);
position: absolute;
left: 0px;
text-align: center;
width: 2.5em;
opacity: 0.5;
vertical-align: top;
}
.li_linenum_before_span_hide{
display: none;
}
.xiaoshujiang_code .code_line_break_hack{
margin:0;
border:0;
border-top:0;
border-bottom:0;
}
/**
* code line nums
*/
.mathjax-container{
text-align: center;
}
div.mathjax{
max-width: 700px;
margin: 0 auto;
font-size: 14px;
}
text{
font-size: 14px;
}
/**
* block image
*/
.story_image_container{
text-align: center;
}
.story_image_container>.story_image{
display: inline-block;
position: relative;
max-width: 80%;
}
.story_image_caption{
border-bottom: 1px solid #d9d9d9;
display: inline-block;
color: #999;
padding: 10px;
}
.story_image_blank_caption{
border-bottom: 0px;
}
/**
.story_image:before, .story_image:after{
content: '';
position: absolute;
z-index: -2;
bottom: 13px;
left: 10px;
width: 50%;
height: 20%;
border-radius: 10px/90px;
box-shadow: 0 15px 10px rgba(0,0,0,0.7);
-webkit-transform: rotate(-3deg);
-moz-transform: rotate(-3deg);
-ms-transform: rotate(-3deg);
-o-transform: rotate(-3deg);
transform: rotate(-3deg);
}
.story_image:after {
right: 10px;
left: auto;
-webkit-transform: rotate(3deg);
-moz-transform: rotate(3deg);
-ms-transform: rotate(3deg);
-o-transform: rotate(3deg);
transform: rotate(3deg);
}
**/
.story_image>img{
border-radius: 0.3125em;
box-shadow: 0 2px 4px 0 rgba(34,36,38,.12),0 2px 10px 0 rgba(34,36,38,.08);
}
.story_inline_image>img{
max-width: 50%;
vertical-align: bottom;
}
.story_remote_resource_block{
text-align: center;
}
.xiaoshujiang_code_container {
margin: 1em 0px;
position: relative;
padding-bottom: 2em;
}
.xiaoshujiang_code_title_container{
font-size: 70%;
opacity: 0.5;
}
.xiaoshujiang_code_title_container>.xiaoshujiang_code_infos{
float: right;
}
.task-list-item{
list-style: none;
}
.task-list-item>input{
margin: 0 0 0 -20px;
}
.video_container{
width: 100%;
display: table;
text-align: center;
position: relative;
padding-bottom: 56.25%!important;
}
.slideshare_container .inner{
position: relative;
width: 100%;
}
.slideshare_container .inner iframe{
width: 100%;
height: 100%;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.video_container iframe{
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 1;
vertical-align: middle;
}
kbd{
display: inline-block;
padding: 3px 5px;
font-size: 11px;
line-height: 10px;
color: #555;
vertical-align: middle;
background-color: #fcfcfc;
border: solid 1px #ccc;
border-bottom-color: #bbb;
border-radius: 3px;
box-shadow: inset 0 -1px 0 #bbb;
}
.blank_anchor_id {
float: left;
}
.blank_anchor_id {
visibility: hidden;
}
.blank_anchor_id:before {
content: 'a';
}
blockquote footer{
margin: 1em 0;
font-style: italic;
}
blockquote footer cite {
margin: 0 1em;
}
/*wavedrom start*/
.wavedrom_svg text, .wavedrom_svg_defs text {
font-size:11pt;
font-style:normal;
font-variant:normal;
font-weight:normal;
font-stretch:normal;
text-align:center;
fill-opacity:1;
font-family:Helvetica
}
.wavedrom_svg .muted, .wavedrom_svg_defs .muted {
fill:#aaa
}
.wavedrom_svg .warning, .wavedrom_svg_defs .warning {
fill:#f6b900
}
.wavedrom_svg .error, .wavedrom_svg_defs .error {
fill:#f60000
}
.wavedrom_svg .info, .wavedrom_svg_defs .info {
fill:#0041c4
}
.wavedrom_svg .success, .wavedrom_svg_defs .success {
fill:#00ab00
}
.wavedrom_svg .h1, .wavedrom_svg_defs .h1 {
font-size:33pt;
font-weight:bold
}
.wavedrom_svg .h2, .wavedrom_svg_defs .h2 {
font-size:27pt;
font-weight:bold
}
.wavedrom_svg .h3, .wavedrom_svg_defs .h3 {
font-size:20pt;
font-weight:bold
}
.wavedrom_svg .h4, .wavedrom_svg_defs .h4 {
font-size:14pt;
font-weight:bold
}
.wavedrom_svg .h5, .wavedrom_svg_defs .h5 {
font-size:11pt;
font-weight:bold
}
.wavedrom_svg .h6, .wavedrom_svg_defs .h6 {
font-size:8pt;
font-weight:bold
}
.wavedrom_svg_defs .s1 {
fill:none;
stroke:#000;
stroke-width:1;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:none
}
.wavedrom_svg_defs .s2 {
fill:none;
stroke:#000;
stroke-width:0.5;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:none
}
.wavedrom_svg_defs .s3 {
color:#000;
fill:none;
stroke:#000;
stroke-width:1;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:1,3;
stroke-dashoffset:0;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s4 {
color:#000;
fill:none;
stroke:#000;
stroke-width:1;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:none;
stroke-dashoffset:0;
marker:none;
visibility:visible;
display:inline;
overflow:visible
}
.wavedrom_svg_defs .s5 {
fill:#fff;
stroke:none
}
.wavedrom_svg_defs .s6 {
color:#000;
fill:#ffffb4;
fill-opacity:1;
fill-rule:nonzero;
stroke:none;
stroke-width:1px;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s7 {
color:#000;
fill:#ffe0b9;
fill-opacity:1;
fill-rule:nonzero;
stroke:none;
stroke-width:1px;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s8 {
color:#000;
fill:#b9e0ff;
fill-opacity:1;
fill-rule:nonzero;
stroke:none;
stroke-width:1px;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s9 {
fill:#000;
fill-opacity:1;
stroke:none
}
.wavedrom_svg_defs .s10 {
color:#000;
fill:#fff;
fill-opacity:1;
fill-rule:nonzero;
stroke:none;
stroke-width:1px;
marker:none;
visibility:visible;
display:inline;
overflow:visible;
enable-background:accumulate
}
.wavedrom_svg_defs .s11 {
fill:#0041c4;
fill-opacity:1;
stroke:none
}
.wavedrom_svg_defs .s12 {
fill:none;
stroke:#0041c4;
stroke-width:1;
stroke-linecap:round;
stroke-linejoin:miter;
stroke-miterlimit:4;
stroke-opacity:1;
stroke-dasharray:none
}
/*wavedrom stop*/
/*
Orginal Style from ethanschoonover.com/solarized (c) Jeremy Hull
*/
.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
background: #fdf6e3;
color: #657b83;
-webkit-text-size-adjust: none;
}
.hljs-comment,
.diff .hljs-header,
.hljs-doctype,
.hljs-pi,
.lisp .hljs-string,
.hljs-javadoc {
color: #93a1a1;
}
/* Solarized Green */
.hljs-keyword,
.hljs-winutils,
.method,
.hljs-addition,
.css .hljs-tag,
.hljs-request,
.hljs-status,
.nginx .hljs-title {
color: #859900;
}
/* Solarized Cyan */
.hljs-number,
.hljs-command,
.hljs-string,
.hljs-tag .hljs-value,
.hljs-rule .hljs-value,
.hljs-phpdoc,
.hljs-dartdoc,
.tex .hljs-formula,
.hljs-regexp,
.hljs-hexcolor,
.hljs-link_url {
color: #2aa198;
}
/* Solarized Blue */
.hljs-title,
.hljs-localvars,
.hljs-chunk,
.hljs-decorator,
.hljs-built_in,
.hljs-identifier,
.vhdl .hljs-literal,
.hljs-id,
.css .hljs-function,
.hljs-name {
color: #268bd2;
}
/* Solarized Yellow */
.hljs-attribute,
.hljs-variable,
.lisp .hljs-body,
.smalltalk .hljs-number,
.hljs-constant,
.hljs-class .hljs-title,
.hljs-parent,
.hljs-type,
.hljs-link_reference {
color: #b58900;
}
/* Solarized Orange */
.hljs-preprocessor,
.hljs-preprocessor .hljs-keyword,
.hljs-pragma,
.hljs-shebang,
.hljs-symbol,
.hljs-symbol .hljs-string,
.diff .hljs-change,
.hljs-special,
.hljs-attr_selector,
.hljs-subst,
.hljs-cdata,
.css .hljs-pseudo,
.hljs-header {
color: #cb4b16;
}
/* Solarized Red */
.hljs-deletion,
.hljs-important {
color: #dc322f;
}
/* Solarized Violet */
.hljs-link_label {
color: #6c71c4;
}
.tex .hljs-formula {
background: #eee8d5;
}
3.scala容器
3.1数组
(1) 定长数组(Array)
//直接声明使用
val array = Array("a","b","c")
//设置数组长度并赋值
val array = new Array[String](3)
array(0) = "a"
array(1) = "b"
array(2) = "c"
(2) 数组缓冲(ArrayBuffer)
数组缓冲是一种可变的数组,类似于Java中的ArrayList,但是ArrayBuffer提供了非常丰富的api
//声明
import scala.collection.multable.ArrayBuffer
val buf = new ArrayBuffer[Int]()
//添加单个元素
buf += 1
//添加多个元素
buf ++= (2,3,4)
//追加一个数组
buf ++= Array(5,6,7)
更多操作可以参考API文档
(3)数组的高级API
//数组内元素求和
Array(1,3,5).sum
//取最大值
Array(1,2,4).max
//排序
val newArray = Array(3,2,5,7,1).sortWith(_>_)
可以自定义排序方法,或者使用scala提供的排序方法,如:
val a = Array(3,2,5,7,1)
//使用快排
scala.util.Sorting.quickSort(a) //不会产生新的数组,原来数组中的元素位置改变
注意:ArrayBuffer不能排序,因为数组缓冲中的元素个数不确定。
(4)与Java互操作
java.util.List转化为scalaArrayBuffer:import scala.collection.JavaConversions.asScalaBuffer
ArrayBuffer转java List: import scala.collection.JavaConversions.bufferAsJavaList
3.2映射
scala中映射也分可变映射和不可变映射。
//创建一个不可变映射
val rank = Map("zs" -> 3,"ls" -> 4)
//创建一个可变的映射,两种方法
val rank = scala.collection.multable.Map("zs" -> 3,"ls" -> 4)
val rank = new scala.collection.multable.Map[String,Int]()
//添加删除元素
rank +=("ww" -> 5,"zl" -> 6)
rank -= "ww"
//更新可变映射
rank("zs") = 30
//迭代映射
for((k,v) <- map){ some code}
3.3元组
元组是一种能存放不同数据类型的容器,一般声明如下:
//声明
val tuple = (11.11,12,"bb")
//遍历
tuple.foreach{}
最新文章
- C#中一些常用的加密和哈希处理
- HMM MEMM &; label bias
- [Hibernate] - EAGER and LAZY
- djangoadmin导出csv
- 点击Listview弹出PopWindow的用法
- android Init 相关分析
- POJ 3287 (基础BFS) Catch That Cow
- opencv 画延长线
- uvalive 4851 Restaurant(扫描法)
- JTextArea自动换行以及设置滚动条
- How to configure ODBC DSN to access local DB2 for Windows
- day27、28 二十八、项目:选课系统
- Android屏幕适配框架-(今日头条终极适配方案)
- 初学者如何迅速学习web前端开发
- Linux 搭建安装Maven环境
- while循环中出现ssh导致读取文件错误
- c#异步等待
- javascript时间日期操作
- git@oschina使用入门(图形界面版)
- sin()函数的实现