📄 str_05.cc
字号:
// file: $isip/class/math/scalar/String/str_05.cc// version: $Id: str_05.cc,v 1.2 2000/11/13 23:37:28 duncan Exp $//// isip include files//#include "String.h"#include <Long.h>#include <Char.h>// method: rand//// arguments:// long min_len: (input) minimum number of characters// long max_len: (input) maximum number of characters//// return: a boolean value indicating status//// randomize the value of this string, restricting all characters to// be alphanumeric or punctuation.//boolean String::rand(long min_len_a, long max_len_a) { // clear the current values // clear(); // determine the new length // Long new_len; new_len.rand(min_len_a, max_len_a); // local variables // Char c; Long num; // loop until we have enough chars // for (long i = 0; i < (long)new_len; ) { num.rand(0, 127); c.assign((unichar)(long)num); if (c.isAlnum() || c.isPunct()) { concat(c); i++; } } // exit gracefully // return true;}// method: hash//// arguments:// long capacity: (input) upper bound on hash value//// return: a hash of the String value//// this is a generic hash function, as defined by Knuth's "The Art of// Computer Programming", volume 3, "Sorting and Searching", chapter// 6.4.//long String::hash(long capacity_a) const { // local variable // ulong hash = 0; // hash function // for (long i = length() - 1; i >= 0; i--) { hash = (hash << 5) ^ (hash >> 27) ^ (ulong)value_d[i]; } // set the modulus to be the capacity - 1, so that the hash will // most likely not be a multiple of 2 or 10 // return (hash % (capacity_a - 1));}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -