PHP 데이터용 DS 확장

巴扎黑
풀어 주다: 2023-03-14 08:24:01
원래의
2059명이 탐색했습니다.

 PHP7 이상에서는 이 데이터 구조 확장만 설치하고 사용할 수 있습니다. 설치는 비교적 간단합니다.

1. 运行命令 pecl install ds

2. 在php.ini中添加 extension=ds.so

3. 重启PHP或重载配置
로그인 후 복사
  • Collection Interface: 모든 데이터 구조의 공통 기능을 포함하는 기본 인터페이스 이 도서관에서. 모든 구조가 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를 사용하여 모든 구조를 탐색하고 계산할 수 있으며 json으로 변환할 수 있음을 보장합니다. Keys.re

    Ds\Hashable {/* 方法 */abstract public bool equals ( object $obj )abstract public mixed hash ( void )
    }
    로그인 후 복사

  • Sequree Interface
  • : A 시퀀스는 피트 전세를 제외하고 1차원 디지털 키 배열과 동일합니다. 사용 사례:

  • 배열을 목록으로 사용하는 모든 곳(키와 관련 없음).
    • SplDoublyLinkedList 및 SplFixedArray에 대한 보다 효율적인 대안.
    • 값은 항상 [ 0으로 인덱싱됩니다. , 1, 2, …, 크기 - 1].
    • [0, 크기 - 1] 범위의 인덱스로만 값에 액세스할 수 있습니다. :A 벡터는 자동으로 늘어나고 줄어드는 연속 버퍼입니다. 가장 효율적인 순차 구조이며 값의 인덱스가 버퍼의 인덱스에 직접 매핑되며 성장 인자는 특정 배수나 지수에 바인딩되지 않습니다. 다음과 같은 장점과 단점이 있습니다.
    • Ds\Vector::allocate — Allocates enough memory  a required capacity.::apply — Updates all values by applying a   to  value.::capacity — Returns the  capacity.::clear — Removes all values.::__construct — Creates a  instance.::contains — Determines  the vector contains given values.:: — Returns a shallow  of the vector.:: — Returns the  of values in the collection.::filter — Creates a  vector using a callable to determine which values to .::find — Attempts to find a value'
      로그인 후 복사

        

      • 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).

    • Deque Class:“双端队列”的缩写,也用于Ds\Queue中,拥有head、tail两个指针。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. 其具有以下优缺点:

      • 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.

      • 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:键值对的连续集合,几乎与数组相同。键可以是任何类型,但必须是唯一的。如果使用相同的键添加到map中,则将替换值。其拥有以下优缺点:

      • 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 an array when objects are used as keys.

    • Pair Class:A pair is used by Ds\Map to pair keys with values.

      Ds\Pair implements JsonSerializable {/* 方法 */public __construct ([ mixed $key [, mixed $value ]] )
      }
      로그인 후 복사

       

    • Set Class唯一值序列。 This implementation uses the same hash table as Ds\Map, where values are used as keys and the mapped value is ignored.其拥有以下优缺点:

      • 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: “last in, first out”集合,只允许在结构顶部进行访问和迭代。

      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 )
      }
      로그인 후 복사

       

    • Queue Class“first in, first out”集合,只允许在结构前端进行访问和迭代。

      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 )
      }
      로그인 후 복사

       

    • PriorityQueue Class:优先级队列与队列是非常相似的,但值以指定的优先级被推入队列,优先级最高的值总是位于队列的前面,同优先级元素“先入先出”顺序任然保留。在一个PriorityQueue上递代是具有破坏性的,相当于连续弹出操作直到队列为空。Implemented using a max heap.

      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 )
      }
      로그인 후 복사

       

위 내용은 PHP 데이터용 DS 확장의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!