PHP中使用BigMap執行個體,PHP使用BigMap執行個體_PHP教程

來源:互聯網
上載者:User

PHP中使用BigMap執行個體,PHP使用BigMap執行個體


<?php//所謂的Bit-map就是用一個bit位來標記某個元素對應的Value, 而Key即是該元素。由於採用了Bit為單位來儲存資料,因此在儲存空間方面,可以大大節省。/*若 N =1 ; 申請記憶體空間為 int a[2] ; 假設需要排序或者尋找的總數N=10000000,那麼我們需要申請記憶體空間的大小為int a[1 + N/32],其中:a[0]在記憶體中佔32為可以對應十進位數0-31,依次類推: 1.求十進位0-N對應在數組a中的下標: n/32 2.求0-N對應0-31中的數: N%32=M3.利用移位0-31使得對應32bit位為1: 1<>SHIFT 這裡相當於 intval($i /32) ; // $i & $this->mask 這裡相當於 $i % $this->mask ,取餘 @$this->bitArray[$i >> $this->shift] &= ~(1<<($i & $this->mask)); }   /** $i 對應的數致1  */ function setbit($i){ @$this->bitArray[$i >> $this->shift] |= (1<<($i & $this->mask)); }  //test 測試所在的bit為是否為1  function testbit($i){ return $this->bitArray[$i >> $this->shift] & (1<<($i & $this->mask)); }   }$oBig = new bigMap() ; $oBig->setbit(30) ; var_dump($oBig->testbit(2)) ; var_dump($oBig->bitArray) ; echo decbin($oBig->bitArray[0]),"
";

http://www.bkjia.com/PHPjc/976029.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/976029.htmlTechArticlePHP中使用BigMap執行個體,PHP使用BigMap執行個體 php//所謂的Bit-map就是用一個bit位來標記某個元素對應的Value, 而Key即是該元素。由於採用了Bit為單位來...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.