一直在考虑怎么存储用户离散的点赞记录,后来用了文件存储和位图做出来的
文件读写的部分参考了别人的写法。
<?php
function get_line_num($value='')
{
if($value%32 == 0)
return ceil($value/32)+1;
else
return ceil($value/32);
}
function get_favour_record($filename, $value=1)
{
if(!file_exists($filename))
return null;
$line = get_line_num($value);
$row_value = get_file_lines($filename, $line);
if($row_value == null)
return null;
return $row_value[$line];
}
function set_favour_record($filename, $value='')
{
if(!file_exists($filename))
return null;
$line = get_line_num($value);
$row_value = get_file_lines($filename, $line);
if($row_value == null){
init_line($filename, $line);
$row_value = get_file_lines($filename, $line);
}
$val = 1<<($value%32);
$row_values = ($row_value[$line])|$val;
change_line($filename, get_line_num