public function setValue($key, $value)
 {
     if ($this->storage !== null) {
         $this->storage->lock();
         $headNode = $this->getHeadNode();
         $headNode->subNode = $this->insert($this->firstNode(), $key, $value);
         $headNode->value = $this->saveNode($headNode->subNode);
         $this->storage->update($headNode->pointer, $headNode->pack());
         $this->storage->unlock();
     } else {
         $this->firstNode = $this->insert($this->firstNode, $key, $value);
     }
 }
Beispiel #2
0
 /**
  * @param NodesProvider $storage
  */
 public function __construct(StorageInterface $storage)
 {
     $node = new Node();
     $node->valueType = 1;
     $data = $node->pack();
     $blockSize = strlen(bin2hex($data)) / 2;
     $storage->setBlockSize($blockSize);
     $storage->lock();
     if ($storage->isEmpty()) {
         $storage->add($data);
     }
     $storage->unlock();
     $this->setStorage($storage);
     $this->setHeadNodePointer(0);
 }