我需要根据联系人姓名从字符串中获取16个(或其他少量)可能的哈希值,用于颜色编码联系人.
我曾尝试获取crc32哈希,然后取第一个符号,即十六进制数字:
$contact = 'Robin Hood';
$colors = [
'0' => 'F8BBD0',
'1' => 'E1BEE7',
...
'e' => 'D7CCC8',
'f' => 'CFD8DC',
];
$firstLetter = hash('crc32', $contact)[0];
return '#' . $colors[$firstLetter];
Run Code Online (Sandbox Code Playgroud)
但是,我怀疑这种方法的良好分布.如何从字符串中获取小的和确定数量的变体?
由于 Drive API 配额、服务配额和脚本执行时间的限制,6 min
将 Google Drive 文件操作拆分成块通常很重要。
我们可以用PropertiesService存储continuationToken
为FolderIterator或FileIterator。这样我们就可以停止我们的脚本,并在下一次运行时从我们停止的地方继续。
// Logs the name of every file in the User's Drive
// this is useful as the script may take more that 5 minutes (max execution time)
var userProperties = PropertiesService.getUserProperties();
var continuationToken = userProperties.getProperty('CONTINUATION_TOKEN');
var start = new Date();
var end = new Date();
var maxTime = 1000*60*4.5; // Max safe time, 4.5 mins
if (continuationToken == …
Run Code Online (Sandbox Code Playgroud)