国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

首頁(yè) 後端開發(fā) php教程 PHP中的資料結(jié)構(gòu):DS擴(kuò)充詳解

PHP中的資料結(jié)構(gòu):DS擴(kuò)充詳解

Feb 07, 2018 am 09:50 AM
php 資料結(jié)構(gòu) 詳解

本文主要為大家?guī)?lái)一篇老生常談PHP中的資料結(jié)構(gòu):DS擴(kuò)充。小編覺得蠻不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟著小編過(guò)來(lái)看看吧,希望能幫助大家。

PHP7以上才能安裝並使用該資料結(jié)構(gòu)擴(kuò)展,安裝比較簡(jiǎn)單:

1. 執(zhí)行指令pecl install ds

2. 在php.ini中新增extension=ds.so

3. 重新啟動(dòng)PHP或重載設(shè)定

Collection Interface:包含本庫(kù)中所有資料結(jié)構(gòu)通用功能的基本interface。 It guarantees that all structures are traversable, countable, and can be converted to json using json_encode().


Ds\Collection implements Traversable , Countable , JsonSerializable {
/* 方法 */
abstract public void clear ( void )
abstract public Ds\Collection copy ( void )
abstract public bool isEmpty ( void )
abstract public array toArray ( void )
}

#Hashable Interface:wich
##

Ds\Hashable {
/* 方法 */
abstract public bool equals ( object $obj )
abstract public mixed hash ( void )
}

Hashable Interface:
wich allows objects toface be used as keys.

Ds\Vector::allocate — Allocates enough memory for a required capacity.
Ds\Vector::apply — Updates all values by applying a callback function to each value.
Ds\Vector::capacity — Returns the current capacity.
Ds\Vector::clear — Removes all values.
Ds\Vector::__construct — Creates a new instance.
Ds\Vector::contains — Determines if the vector contains given values.
Ds\Vector::copy — Returns a shallow copy of the vector.
Ds\Vector::count — Returns the number of values in the collection.
Ds\Vector::filter — Creates a new vector using a callable to determine which values to include.
Ds\Vector::find — Attempts to find a value's index.
Ds\Vector::first — Returns the first value in the vector.
Ds\Vector::get — Returns the value at a given index.
Ds\Vector::insert — Inserts values at a given index.
Ds\Vector::isEmpty — Returns whether the vector is empty
Ds\Vector::join — Joins all values together as a string.
Ds\Vector::jsonSerialize — Returns a representation that can be converted to JSON.
Ds\Vector::last — Returns the last value.
Ds\Vector::map — Returns the result of applying a callback to each value.
Ds\Vector::merge — Returns the result of adding all given values to the vector.
Ds\Vector::pop — Removes and returns the last value.
Ds\Vector::push — Adds values to the end of the vector.
Ds\Vector::reduce — Reduces the vector to a single value using a callback function.
Ds\Vector::remove — Removes and returns a value by index.
Ds\Vector::reverse — Reverses the vector in-place.
Ds\Vector::reversed — Returns a reversed copy.
Ds\Vector::rotate — Rotates the vector by a given number of rotations.
Ds\Vector::set — Updates a value at a given index.
Ds\Vector::shift — Removes and returns the first value.
Ds\Vector::slice — Returns a sub-vector of a given range.
Ds\Vector::sort — Sorts the vector in-place.
Ds\Vector::sorted — Returns a sorted copy.
Ds\Vector::sum — Returns the sum of all values in the vector.
Ds\Vector::toArray — Converts the vector to an array.
Ds\Vector::unshift — Adds values to the front of the vector.

Sequence Interface:

A Sequence 相當(dāng)於一個(gè)一維的數(shù)字key數(shù)組, with the exception of a few characteristics:

Values will always be indexed as [0, 1, 2, …, size - 1].

Only allowed to access values by index in the range [0, size - 1].

Use cases:

Wherever you would use an array as a list (not concerned with keys).

A more efficient alternative to SplDoublyLinkedList and SplFixedArray.

Vector Class:

Vector是自動(dòng)增長(zhǎng)和收縮的連續(xù)緩衝區(qū)中的一系列值。它是最有效的順序結(jié)構(gòu),值的索引直接映射到緩衝區(qū)中索引,增長(zhǎng)因子不綁定到特定的倍數(shù)或指數(shù)。其有以下優(yōu)缺點(diǎn):

Supports array syntax (square brackets).

Uses less overall memory than an array for the same number of values.

#Automatically frees allocated memory when its size drops low enough.

Capacity does not have to be a power of 2.get(), set(), push(), pop() are all O(1 ).


但是shift(), unshift(), insert() and remove() are all O(n).

Ds\Pair implements JsonSerializable {
/* 方法 */
public __construct ([ mixed $key [, mixed $value ]] )
}

Deque Class:

「雙端佇列」的縮寫,也用於Ds\Queue中,擁有head、tail兩個(gè)指標(biāo)。 The pointers can “wrap around” the end of the buffer, which avoids the need to move other values around to make room. This makes shift and unshift very fast?—? something a Ds\Vector can't compete with. 其具有以下優(yōu)缺點(diǎn):

Supports array syntax (square brackets).

Uses less overall memory than an array for the same number of values.

Automatically frees allocated memory when ops ize

Automatically frees allocated memory when ops size 一樣enough.get(), set(), push(), pop(), shift(), and unshift() are all O(1).

但Capacity must be a power of 2.insert() and remove() are O(n).

Map Class:

鍵值對(duì)的連續(xù)集合,幾乎與陣列相同。鍵可以是任何類型,但必須是唯一的。如果使用相同的鍵新增到map中,則將替換值。其擁有以下優(yōu)缺點(diǎn):

Keys and values can be any type, including objects.

Supports array syntax (square brackets).

##Insertion order is preserved.

Performance and memory efficiency is very similar to an array.

Automatically frees allocated memory when its size drops low enough.

Can't be converted to anopsy whenen objects are used as keys.


Pair Class:

A pair is used by Ds\Map to pair keys with values.

#

Ds\Stack implements Ds\Collection {
/* 方法 */
public void allocate ( int $capacity )
public int capacity ( void )
public void clear ( void )
public Ds\Stack copy ( void )
public bool isEmpty ( void )
public mixed peek ( void )
public mixed pop ( void )
public void push ([ mixed $...values ] )
public array toArray ( void )
}

Set Class:

唯一值序列。 This implementation uses the same hash table as Ds\Map, where values are used as keys and the mapped value is ignored.其擁有以下優(yōu)缺點(diǎn):

Values can be any type, including objects.

Supports array syntax (square brackets).

Insertion order is preserved.

Automatically frees allocated memory when its size drops low enough.##add(), remove ) and contains() are all O(1).

但Doesn't support push(), pop(), insert(), shift(), or unshift(). get() is O(n) if there are deleted values in the buffer before the accessed index, O(1) otherwise.


Stack Class:

“l(fā)ast in, first out”集合,只允許在結(jié)構(gòu)頂部進(jìn)行訪問和迭代。

Ds\Queue implements Ds\Collection {
/* Constants */
const int MIN_CAPACITY = 8 ;
/* 方法 */
public void allocate ( int $capacity )
public int capacity ( void )
public void clear ( void )
public Ds\Queue copy ( void )
public bool isEmpty ( void )
public mixed peek ( void )
public mixed pop ( void )
public void push ([ mixed $...values ] )
public array toArray ( void )
}


Queue Class:

「first in, first out」集合,只允許在結(jié)構(gòu)前端進(jìn)行存取和迭代。

Ds\PriorityQueue implements Ds\Collection {
/* Constants */
const int MIN_CAPACITY = 8 ;
/* 方法 */
public void allocate ( int $capacity )
public int capacity ( void )
public void clear ( void )
public Ds\PriorityQueue copy ( void )
public bool isEmpty ( void )
public mixed peek ( void )
public mixed pop ( void )
public void push ( mixed $value , int $priority )
public array toArray ( void )
}


PriorityQueue Class:

優(yōu)先權(quán)佇列與佇列是非常相似的,但值以指定的優(yōu)先權(quán)被推入佇列,優(yōu)先權(quán)最高的值總是位於佇列的前面,同優(yōu)先權(quán)元素「先入先出」順序任然保留。在一個(gè)PriorityQueue上遞代是具有破壞性的,相當(dāng)於連續(xù)彈出操作直到隊(duì)列為空。 Implemented using a max heap.


rrreee相關(guān)推薦:

######PHP實(shí)作堆疊資料結(jié)構(gòu)與括號(hào)符合##### #

PHP堆疊資料結(jié)構(gòu)與括號(hào)匹配演算法實(shí)例講解

#php資料結(jié)構(gòu)之順序鍊錶與鍊式線性表示例

#

以上是PHP中的資料結(jié)構(gòu):DS擴(kuò)充詳解的詳細(xì)內(nèi)容。更多資訊請(qǐng)關(guān)注PHP中文網(wǎng)其他相關(guān)文章!

本網(wǎng)站聲明
本文內(nèi)容由網(wǎng)友自願(yuàn)投稿,版權(quán)歸原作者所有。本站不承擔(dān)相應(yīng)的法律責(zé)任。如發(fā)現(xiàn)涉嫌抄襲或侵權(quán)的內(nèi)容,請(qǐng)聯(lián)絡(luò)admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費(fèi)脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅(qū)動(dòng)的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費(fèi)的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費(fèi)的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強(qiáng)大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6

Dreamweaver CS6

視覺化網(wǎng)頁(yè)開發(fā)工具

SublimeText3 Mac版

SublimeText3 Mac版

神級(jí)程式碼編輯軟體(SublimeText3)

如何在PHP中牢固地處理文件上傳? 如何在PHP中牢固地處理文件上傳? Jul 08, 2025 am 02:37 AM

要安全處理PHP文件上傳需驗(yàn)證來(lái)源與類型、控製文件名與路徑、設(shè)置服務(wù)器限制並二次處理媒體文件。 1.驗(yàn)證上傳來(lái)源通過(guò)token防止CSRF並通過(guò)finfo_file檢測(cè)真實(shí)MIME類型使用白名單控制;2.重命名文件為隨機(jī)字符串並根據(jù)檢測(cè)類型決定擴(kuò)展名存儲(chǔ)至非Web目錄;3.PHP配置限制上傳大小及臨時(shí)目錄Nginx/Apache禁止訪問上傳目錄;4.GD庫(kù)重新保存圖片清除潛在惡意數(shù)據(jù)。

您如何按值與PHP中的參考傳遞變量? 您如何按值與PHP中的參考傳遞變量? Jul 08, 2025 am 02:42 AM

InPHP,variablesarepassedbyvaluebydefault,meaningfunctionsorassignmentsreceiveacopyofthedata,whilepassingbyreferenceallowsmodificationstoaffecttheoriginalvariable.1.Whenpassingbyvalue,changestothecopydonotimpacttheoriginal,asshownwhenassigning$b=$aorp

PHP標(biāo)頭位置AJAX調(diào)用不起作用 PHP標(biāo)頭位置AJAX調(diào)用不起作用 Jul 10, 2025 pm 01:46 PM

AJAX請(qǐng)求中header('Location:...')無(wú)效的原因是瀏覽器不會(huì)自動(dòng)執(zhí)行頁(yè)面跳轉(zhuǎn)。因?yàn)樵贏JAX請(qǐng)求中,服務(wù)器返回的302狀態(tài)碼和Location頭信息會(huì)被作為響應(yīng)數(shù)據(jù)處理,而不是觸發(fā)跳轉(zhuǎn)行為。解決方法有:1.在PHP中返回JSON數(shù)據(jù)包含跳轉(zhuǎn)URL;2.在前端AJAX回調(diào)中檢查redirect字段並用window.location.href手動(dòng)跳轉(zhuǎn);3.確保PHP輸出僅為JSON避免解析失??;4.處理跨域問題需設(shè)置合適的CORS頭;5.防止緩存干擾可加時(shí)間戳或設(shè)置cache:f

發(fā)電機(jī)如何在PHP中工作? 發(fā)電機(jī)如何在PHP中工作? Jul 11, 2025 am 03:12 AM

AgeneratorinPHPisamemory-efficientwaytoiterateoverlargedatasetsbyyieldingvaluesoneatatimeinsteadofreturningthemallatonce.1.Generatorsusetheyieldkeywordtoproducevaluesondemand,reducingmemoryusage.2.Theyareusefulforhandlingbigloops,readinglargefiles,or

PHP找到了最後一次發(fā)生的位置 PHP找到了最後一次發(fā)生的位置 Jul 09, 2025 am 02:49 AM

在PHP中查找子字符串最後一次出現(xiàn)的位置,最直接的方法是使用strrpos()函數(shù)。 1.使用strrpos()函數(shù)可直接獲取子字符串在主字符串中最後一次出現(xiàn)的起始位置索引,若未找到則返回false,語(yǔ)法為strrpos($haystack,$needle,$offset=0)。 2.若需忽略大小寫,可使用strripos()函數(shù)實(shí)現(xiàn)不區(qū)分大小寫的查找。 3.對(duì)於中文等多字節(jié)字符,應(yīng)使用mbstring擴(kuò)展中的mb_strrpos()函數(shù)以確保返回字符位置而非字節(jié)位置。 4.注意strrpos()返回f

如何防止PHP中的會(huì)話劫持? 如何防止PHP中的會(huì)話劫持? Jul 11, 2025 am 03:15 AM

要防止PHP中的會(huì)話劫持,需採(cǎi)取以下措施:1.使用HTTPS加密傳輸並在php.ini中設(shè)置session.cookie_secure=1;2.設(shè)置安全Cookie屬性,包括httponly、secure和samesite;3.在用戶登錄或權(quán)限變更時(shí)調(diào)用session_regenerate_id(true)更換SessionID;4.限制Session生命週期,合理配置gc_maxlifetime並記錄用戶活動(dòng)時(shí)間;5.禁止將SessionID暴露在URL中,設(shè)置session.use_only

php獲得字符串的第一個(gè)N字符 php獲得字符串的第一個(gè)N字符 Jul 11, 2025 am 03:17 AM

在PHP中取字符串前N個(gè)字符可用substr()或mb_substr(),具體步驟如下:1.使用substr($string,0,N)截取前N個(gè)字符,適用於ASCII字符且簡(jiǎn)單高效;2.處理多字節(jié)字符(如中文)時(shí)應(yīng)使用mb_substr($string,0,N,'UTF-8'),並確保啟用mbstring擴(kuò)展;3.若字符串含HTML或空白字符,應(yīng)先用strip_tags()去除標(biāo)籤、trim()清理空格,再截取以保證結(jié)果乾淨(jìng)。

如何用urlencode在PHP中編碼字符串 如何用urlencode在PHP中編碼字符串 Jul 11, 2025 am 03:22 AM

urlencode()函數(shù)用於將字符串編碼為URL安全格式,其中非字母數(shù)字字符(除-、_和.外)會(huì)被替換為百分號(hào)後跟兩位十六進(jìn)制數(shù)的形式。例如,空格轉(zhuǎn)為 號(hào),感嘆號(hào)轉(zhuǎn)為!,而中文字符則轉(zhuǎn)換為其UTF-8編碼形式。使用時(shí)應(yīng)僅對(duì)參數(shù)值進(jìn)行編碼,而非整個(gè)URL,以避免破壞URL結(jié)構(gòu)。對(duì)於URL的其他部分如路徑段,應(yīng)使用rawurlencode()函數(shù),其將空格轉(zhuǎn)為 。處理數(shù)組參數(shù)時(shí)可使用http_build_query()自動(dòng)編碼,或手動(dòng)對(duì)每個(gè)值調(diào)用urlencode()以確保安全傳輸數(shù)據(jù)。正

See all articles