Skip to content

Commit

Permalink
Update YADWord.php
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan committed May 26, 2014
1 parent 18fd787 commit f4c6efb
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions YADWord.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public function __construct($w, $r, $s, $ss){
$this->region_id = (int)$r;
$this->original = $w;
$this->word = self::prepare($w);
$this->strict = '!'.str_replace(' ', ' !', $this->word);
$this->strict = '"!'.str_replace(' ', ' !', $this->word).'"';
$this->crc = crc32(str_replace(' ','-',$this->word));
$this->hash = crc32(str_replace(' ','-',$this->word).'-'.$this->region_id);
$this->stat = (int)$s;
$this->stat_strict = (int)$ss;

Expand All @@ -33,8 +34,27 @@ public function __construct($w, $r, $s, $ss){
self::$bind_crc[$this->crc][] = &$this;
}

public static function count($repeat = false){
if(!$repeat) return count(self::$bind_crc);
$i = 0;
foreach (self::$bind_crc as $crc => $a){
$i += count($a);
}
return $i;
}

public function setStat($stat){
$this->stat = $stat;
}

public function setStatStrict($stat){
$this->stat_strict = $stat;
}

public static function get($w, $r, $stat = -1, $stat_strict = -1){
if($i = self::findByRegionCRC($w, $r)){
if($stat >= 0) $i->stat = $stat;
if($stat_strict >= 0) $i->stat_strict = $stat_strict;
return $i;
}

Expand All @@ -43,17 +63,17 @@ public static function get($w, $r, $stat = -1, $stat_strict = -1){
return $i;
}

public static function findComplete($region_id){
return self::findByStatus(true, $region_id);
public static function findComplete($region_id = false, $limit = false){
return self::findByStatus(true, $region_id, $limit);
}

public static function findIncomplete($region_id = false){
return self::findByStatus(false, $region_id);
public static function findIncomplete($region_id = false, $limit = false){
return self::findByStatus(false, $region_id, $limit);
}

public static function findByStatus($complete, $region_id){
public static function findByStatus($complete, $region_id, $limit = false){
$l = array();

$i = 0;
$complete = (boolean)$complete;

if($region_id){
Expand All @@ -65,15 +85,19 @@ public static function findByStatus($complete, $region_id){
foreach(self::$bind_region[$region_id] as $crc => $c){
if(($complete == false && ($c->stat < 0 || $c->stat_strict < 0)) || ($complete == true && $c->stat >= 0 && $c->stat_strict >= 0)){
$l[] = $c;
$i++;
}
if($limit && $limit <= $i) break 2;
}
}
}else{
foreach (self::$bind_crc as $cc){
foreach($cc as $crc => $c){
if(($complete == false && ($c->stat < 0 || $c->stat_strict < 0)) || ($complete == true && $c->stat >= 0 && $c->stat_strict >= 0)){
$l[] = $c;
$i++;
}
if($limit && $limit <= $i) break 2;
}
}
}
Expand Down Expand Up @@ -111,6 +135,10 @@ public static function findByRegion($r, $filter = array()){
if($crc != $val)
continue 2;
break;
case 'hash':
if($c->hash != $val)
continue 2;
break;
}
}
$l[] = &$c;
Expand Down

0 comments on commit f4c6efb

Please sign in to comment.