Subversion Repositories Filer-Free

Compare Revisions

Ignore whitespace Rev 60 → Rev 61

/trunk/filer/pathname_hash.h
New file
0,0 → 1,23
// This file is part of the free Filer module for RISC OS.
// Copyright © 2007 Graham Shaw.
// Redistribution and modification are permitted under the terms of the
// GNU General Public License (version 2 or any later version).
 
#ifndef FILER_PATHNAME_HASH
#define FILER_PATHNAME_HASH
 
/** Calculate hash of pathname.
* Callers should not make any assumption about how the hash is calculated,
* except that it is consistent for any given set of inputs.
* @param pathname the pathname (which should exclude the filing system and
* special field
* @param length the length of the pathname
* @param fs_number the filing system number
* @param fs_special the filing system special field (null terminated),
* or 0 if none
*/
extern "C"
unsigned int pathname_hash(const char* pathname,unsigned int length,
int fs_number,const char* fs_special);
 
#endif
/trunk/filer/pathname_hash.s
New file
0,0 → 1,43
; This file is part of the free Filer module for RISC OS.
; Copyright © 2007 Graham Shaw.
; Redistribution and modification are permitted under the terms of the
; GNU General Public License (version 2 or any later version).
 
AREA |C$$Code|,CODE,READONLY,REL
 
; Calculate hash of pathname.
;
; On entry:
; R0=pathname (which should exclude the filing system and special field)
; R1=length of pathname
; R2=filing system number
; R3=filing system special field (null terminated), or 0 if none
; On exit:
; R0=hash
; R1-R3,R12 corrupted
 
EXPORT |pathname_hash|
|pathname_hash|
; R2=hash (start with filing system number)
MOV R2,R2,ROR#23 ; Rotate hash left by 1 byte
 
TEQ R3,#0 ; Check whether special field specified
|pathname_hash_0|
LDRNEB R12,[R3],#1 ; R12=char from special field
TEQNE R12,#0 ; Check for terminator, exit loop if found
ADDNE R2,R2,R12 ; Add to hash
MOVNE R2,R2,ROR#24 ; Rotate hash left by 1 byte
BNE |pathname_hash_0| ; Repeat until end of special field
 
TEQ R1,#0 ; Check for end of pathname
|pathname_hash_1|
LDRNEB R12,[R0],#1 ; R12=byte from pathname
ADDNE R2,R2,R12 ; Add to hash
MOVNE R2,R2,ROR#24 ; Rotate hash left by 1 byte
SUBNES R1,R1,#1 ; Decrement bytes remaining
BNE |pathname_hash_1| ; Repeat until end of pathname
 
MOV R0,R2 ; R0=hash
MOV PC,LR ; Return
 
END