Download the PHP package pwm/bitset without Composer

On this page you can find all versions of the php package pwm/bitset. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package bitset

BitSet

Build Status codecov Maintainability Test Coverage License: MIT

A simple bit set implementation for compact storage of sets of values. The library itself is stateless providing only pure mapping functions.

Table of Contents

Requirements

PHP 7.1+

Installation

$ composer require pwm/bitset

Usage

In this example we are going to use a bit set to put users in groups.

Let's create a Group class. It has a list of groups, named G1 to G5 for this example, and a map between groups and binary values of powers of 2 provided by BitSet. Finally it has 2 functions that map between group names and bit values.

Let's also create a User class. A user can belong to groups. The $groups property starts from 0 that represents the empty set. It has 5 methods to manipulate its groups, corresponding to BitSet's 5 functions: get(), set(), add(), remove() and has().

Now we can use the above the following way:

How it works

As an example let's take the numbers 1, 4 and 8. Their sum is 13. Pretty uninteresting so far. But let's look at their binary representations: 0b1, 0b100 and 0b1000 respectively. Their sum 13 is 0b1101. See how the base-2 representations of 1, 4 and 8 "fill unique slots" in 13's, leaving only one slot unset? This is because 1, 4 and 8 are all powers of 2 so their binary representations starts with a 1 followed by zero or more 0s. 0b1 = 2^0 = 1, 0b100 = 2^2 = 4, 0b1000 = 2^3 = 8. Their sum: 2^0 + 2^2 + 2^3 = 0b1 + 0b100 + 0b1000 = 0b1101 = 13. Now, say in a game, we could call 1 "north", 2 "south", 4 "east" and 8 "west" and then 13 could mean that our character can move all directions from its current position except south as 2 (0b10) is not in 13 (0b1101).

The idea behind a bit set is using a base-2 representation of a number to singal the presence or absence of values by having its bits set to 1 or 0. The values themselves are also numbers with the restriction that they must be powers of 2 starting from 2^0 and in general, depending on the underlying system, going up to 2^32 or 2^64. For example on a 64 bit system one can store up to 64 unique values in a bit set.

The BitSet library itself is a collection of 5 pure functions that map between values and their bit set:

set(array $values): int

Maps a list of unique positive integers to a single integer, the bit set, that is their sum. All integers in the input list must be powers of 2.

get(int $bitSet): array

Maps an integer, the bit set, to a list of unique positive integers. All integers in the output list must be powers of 2.

add(int $bitSet, array $values): int

Adds a list of unique positive integers to a bit set. All integers in the list must be powers of 2.

remove(int $bitSet, array $values): int

Subtracts a list of unique positive integers from a bit set. All integers in the list must be powers of 2.

has(int $bitSet, int $value): bool

Predicate that tells whether an element is in a bit set or not.

Tests

$ vendor/bin/phpunit
$ composer phpcs
$ composer phpstan

Changelog

Click here

Licence

MIT


All versions of bitset with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pwm/bitset contains the following files

Loading the files please wait ....